How do I sort a data.frame with one column?
I'm using the following:
> set.seed(456)
> df1 <- data.frame(col1 = runif(10))
> class(df1)
[1] "data.frame"
> df1 <- df1[order(df1$col1),]
> class(df1)
[1] "numeric"
However if I add a blank column things work fine:
> set.seed(456)
> df1 <- data.frame(col1 = runif(10))
> df1$dummy <- NA
> class(df1)
[1] "data.frame"
> df1 <- df1[order(df1$col1),]
> class(df1)
[1] "data.frame"
> df1 
         col1 dummy
7  0.08243274    NA
1  0.08955160    NA
2  0.21051232    NA
9  0.23750327    NA
8  0.28552695    NA
6  0.33195997    NA
10 0.38523617    NA
3  0.73295527    NA
5  0.78839789    NA
4  0.85213354    NA
Is there a better way to do this?
 
     
     
     
     
    