geo_dd geo_dd - 1 year ago 102
R Question

Mixedorder data frame in R

I have a data frame which looks like this :

a = c("1A","10A","11A","2B","2C","22C","3A","3B")
b= c(1,2,3,4,5,6,7,8)
ab = data.frame(a,b)

and I want to sort it according to the column
. I tried the mixed order


but I don' t get the result I want (1A,2B,2C,3A,3B..).
How can I fix this?

Answer Source

We need to convert to character class (as the 'a' column is factor based on the default option in data.frame call i.e. stringsAsFactors=TRUE)

#    a b
#1  1A 1
#4  2B 4
#5  2C 5
#7  3A 7
#8  3B 8
#2 10A 2
#3 11A 3
#6 22C 6

Additional options are also explained in here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download