R-help, Long ago I asked how to sort a data frame according to one of the columns. But Iwas wondering ho I could "double sort" , i.e, sort according to one column and another one afterwards. It is quite easy in Excel but I am unable to implemented in R. I have searched in the R help archives and found nothing. Thank you in advance.
> class(df)[1] data.frame> names(df)[1] "x" "y" "z" df <- df[order(df$x, df$y),] # sort df by x and y with priority to x -----Message d'origine----- De : r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]De la part de Luis Ridao Cruz Envoye : vendredi 11 fevrier 2005 16:03 A : r-help at stat.math.ethz.ch Objet : [R] Double sort a data frame R-help, Long ago I asked how to sort a data frame according to one of the columns. But Iwas wondering ho I could "double sort" , i.e, sort according to one column and another one afterwards. It is quite easy in Excel but I am unable to implemented in R. I have searched in the R help archives and found nothing. Thank you in advance. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Hi, you can use order, like DATA <- DATA[order(DATA$V1, DATA$V2), ] best jan On Fri, 11 Feb 2005, Luis Ridao Cruz wrote:> R-help, > > Long ago I asked how to sort a data frame according to one of the > columns. > But Iwas wondering ho I could "double sort" , i.e, sort according to > one column and another one afterwards. > It is quite easy in Excel but I am unable to implemented in R. > > > I have searched in the R help archives and found nothing. > > > Thank you in advance. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- +----------------------------------------- Jan Goebel j g o e b e l @ d i w . d e DIW Berlin German Socio-Economic Panel Study (GSOEP) K?nigin-Luise-Str. 5 D-14195 Berlin -- Germany -- phone: 49 30 89789-377 +-----------------------------------------
> From: Luis Ridao Cruz > > R-help, > > Long ago I asked how to sort a data frame according to one of the > columns. > But Iwas wondering ho I could "double sort" , i.e, sort according to > one column and another one afterwards. > It is quite easy in Excel but I am unable to implemented in R.Just as easy in R, if not easier. Something like: dat[order(dat$col1, dat$col2), ]> I have searched in the R help archives and found nothing.This has been asked (and answered) numerous times on this list. There was a function posted for Kevin Wright that implements a formula interface for sorting data frames. Andy> Thank you in advance. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
?order On Fri, 11 Feb 2005, Luis Ridao Cruz wrote:> R-help, > > Long ago I asked how to sort a data frame according to one of the > columns. > But Iwas wondering ho I could "double sort" , i.e, sort according to > one column and another one afterwards. > It is quite easy in Excel but I am unable to implemented in R. > > > I have searched in the R help archives and found nothing. > > > Thank you in advance. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
You are right Andy, I just found on the archives soon after I tried searching for a second time. Sorry Luis>>> "Liaw, Andy" <andy_liaw at merck.com> 11/02/2005 13:15:16 >>> > From: Luis Ridao Cruz > > R-help, > > Long ago I asked how to sort a data frame according to one of the > columns. > But Iwas wondering ho I could "double sort" , i.e, sort according to > one column and another one afterwards. > It is quite easy in Excel but I am unable to implemented in R.Just as easy in R, if not easier. Something like: dat[order(dat$col1, dat$col2), ]> I have searched in the R help archives and found nothing.This has been asked (and answered) numerous times on this list. There was a function posted for Kevin Wright that implements a formula interface for sorting data frames. Andy> Thank you in advance. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}