Hi!

I think this is an important example! Is there a way to make it included in the help of order?

Maybe a shortened version:

# sorting a data frame
df <- data.frame(V1 = c("W","A", "A", "B", ""), V2 = c("E", "M", "B", "O", "Q"))
sorted <- df[order(df$V1, df$V2), ]



And a question: what to do to have the sorted data frame with the row labels 1:n?


Gábor

----------------------------------------------------------------
Marc Schwartz írta:
On Wed, 2003-07-16 at 08:42, Wayne Jones wrote:
Does anyone know if it is possible to sort a dataframe?

Example:

# Create two column df
df <- data.frame(V1 = c("W","A", "A", "B", ""), V2 = c("E", "M", "B", "O", "Q"))
# show df unsorted
df


  V1 V2
1  W  E
2  A  M
3  A  B
4  B  O
5     Q

# now sort df, by V1, then V2
df[order(df$V1, df$V2), ]

  V1 V2
5     Q
3  A  B
2  A  M
4  B  O
1  W  E

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to