Re: [R] sort a data matrix by all the values and keep the names

2008-09-22 Thread hadley wickham
gt; x1 x2 x3 > 1 1 4 8 > 2 7 6 2 >> melt(x, id = c()) > Error in if (!missing(id.var) && !(id.var %in% varnames)) { : > missing value where TRUE/FALSE needed >> > > > Steve McKinney > > > -Original Message----- > From: [EMAIL PROTECTE

Re: [R] sort a data matrix by all the values and keep the names

2008-09-22 Thread Steven McKinney
From: [EMAIL PROTECTED] on behalf of hadley wickham Sent: Mon 9/22/2008 5:47 PM To: zhihuali Cc: [EMAIL PROTECTED] Subject: Re: [R] sort a data matrix by all the values and keep the names On Mon, Sep 22, 2008 at 6:54 PM, zhihuali <[EMAIL PROTECTED]> wrote: > > Dear all, > > If

Re: [R] sort a data matrix by all the values and keep the names

2008-09-22 Thread zhihuali
This is exactly what I wanted! Thank you so much! Z > Date: Mon, 22 Sep 2008 19:21:43 -0500 > From: [EMAIL PROTECTED] > Subject: RE: [R] sort a data matrix by all the values and keep the names > To: [EMAIL PROTECTED] > > Hi: there might be a quicker way but you can u

Re: [R] sort a data matrix by all the values and keep the names

2008-09-22 Thread hadley wickham
On Mon, Sep 22, 2008 at 6:54 PM, zhihuali <[EMAIL PROTECTED]> wrote: > > Dear all, > > If I have a data frame x<-data.frame(x1=c(1,7),x2=c(4,6),x3=c(8,2)): > x1 x2 x3 > 1 4 8 > 7 6 2 > > I want to sort the whole data and get this: > x1 1 > x3 2 > x2 4 > x2 6 > x1 7 > x3 8

Re: [R] sort a data matrix by all the values and keep the names

2008-09-22 Thread Moshe Olshansky
One possibility is: > x <- data.frame(x1=c(1,7),x2=c(4,6),x3=c(8,2)) > names <- t(matrix(rep(names(x),times=nrow(x)),nrow=ncol(x))) > m <- as.matrix(x) > ind <- order(m) > df <- data.frame(name=names[ind],value=m[ind]) > df name value 1 x1 1 2 x3 2 3 x2 4 4 x2 6 5 x1