Hi, I've got a problem which seemed simple to me at first view, but which I haven't managed to solve yet. I have a dataframe, or a matrix, and I would like to order it along with one of the variables/columns. I tried to use order() but it remained quite unclear to me. How should I proceed ? Thanks in advance (I guess that's not very difficult a question for most of you) Laurent
I've used 'order' successfully. Consider the following: df1 <- data.frame(x=rnorm(9)) df1 df1[order(df1$x),, drop=F] If you provide an example of what did not work, someone might be able to help more. spencer graves Laurent Faisnel wrote:> Hi, > I've got a problem which seemed simple to me at first view, but which I > haven't managed to solve yet. I have a dataframe, or a matrix, and I > would like to order it along with one of the variables/columns. I tried > to use order() but it remained quite unclear to me. How should I proceed ? > Thanks in advance (I guess that's not very difficult a question for most > of you) > > Laurent > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
On Wed, 07 May 2003 18:20:43 +0200, you wrote in message <3EB9325B.4010906 at ariase.com>:>Hi, >I've got a problem which seemed simple to me at first view, but which I >haven't managed to solve yet. I have a dataframe, or a matrix, and I >would like to order it along with one of the variables/columns. I tried >to use order() but it remained quite unclear to me. How should I proceed ? >Thanks in advance (I guess that's not very difficult a question for most >of you)Try something like this: x <- matrix(rnorm(100),10,10) s <- x[order(x[,1]),] Now s is a copy of x sorted on the first column. Duncan Murdoch
mydf[order(mydf$colname), ] Best, Philippe Grosjean ...........]<(({?<...............<?}))><............................... ) ) ) ) ) ( ( ( ( ( Dr. Philippe Grosjean ) ) ) ) ) ( ( ( ( ( LOV, UMR 7093 ) ) ) ) ) Station Zoologique ( ( ( ( ( Observatoire Oceanologique ) ) ) ) ) BP 28 ( ( ( ( ( 06234 Villefranche sur mer cedex ) ) ) ) ) France ( ( ( ( ( ) ) ) ) ) tel: +33.4.93.76.38.18, fax: +33.4.93.76.38.34 ( ( ( ( ( ) ) ) ) ) e-mail: phgrosjean at sciviews.org ( ( ( ( ( SciViews project coordinator (http://www.sciviews.org) ) ) ) ) ) ....................................................................... -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Laurent Faisnel Sent: mercredi 7 mai 2003 6:21 To: r-help at stat.math.ethz.ch Subject: [R] how to order a dataframe ? Hi, I've got a problem which seemed simple to me at first view, but which I haven't managed to solve yet. I have a dataframe, or a matrix, and I would like to order it along with one of the variables/columns. I tried to use order() but it remained quite unclear to me. How should I proceed ? Thanks in advance (I guess that's not very difficult a question for most of you) Laurent ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help