How to sort a data frame row/column wise according to alphanumeric values in R?

r

#1

Hello,

I want to sort alphanumeric values in my data frame row/column wise. Suppose i have a data frame->

x=c(‘A2’,‘B5’,‘H4’,‘J9’,‘F3’)
y=c(‘S5’,‘A1’,‘B9’,‘V0’,‘S4’)
z=c(‘D6’,‘T4’,‘Q2’,‘M3’,‘L8’)
data=data.frame(x,y,z)
data
x y z
1 A2 S5 D6
2 B5 A1 T4
3 H4 B9 Q2
4 J9 V0 M3
5 F3 S4 L8

Then I want that row 1 becomes A2 D6 S5, row 2 becomes A1 B5 T4 and so on… How can I do this?

Thanks


#2
as.data.frame(t(apply(data, 1, sort)))
  V1 V2 V3
1 A2 D6 S5
2 A1 B5 T4
3 B9 H4 Q2
4 J9 M3 V0
5 F3 L8 S4