Re: [R] sorting a matrix by the column

2009-02-11 Thread jim holtman
Use 'drop=FALSE' > temp2 <- matrix(rnorm(10),nc=1) > rownames(temp2) <- c("a","b","c","d","e","f","g","h","i",'j') > print(temp2) [,1] a -0.5686687 b -0.1351786 c 1.1780870 d -1.5235668 e 0.5939462 f 0.3329504 g 1.0630998 h -0.3041839 i 0.3700188 j 0.2670988 > temp2 <- temp2[order(te

Re: [R] sorting a matrix by the column

2009-02-11 Thread Gabor Grothendieck
This is what I get: > temp2 <- matrix(rnorm(10),nc=1,nrow=5) > rownames(temp2) <- c("a","b","c","d","e","f","g","h","i") Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array extent > R.version.string [1] "R version 2.8.1 Patched (2008-12-26 r47350)" On Wed, Feb 11, 2009 at 1

[R] sorting a matrix by the column

2009-02-10 Thread markleeds
this is a bad question but I can't figure it out and i've tried. if i sort the 2 column matrix , temp1, by the first column, then things work as expected. But, if I sort the 1 column matrix, temp2, then it gets turned coerced to a vector. I realize that I need to use drop=FALSE but i've put it i

Re: [R] Sorting a matrix by a column

2008-08-04 Thread Dimitris Rizopoulos
probably you need order(), e.g., data[order(data[, 2]), ] I hope it helps. Best, Dimitris John Sorkin wrote: R 2.6 Windows XP I have a 100x4 matirx data<-matrix(nrow=100,ncol=4) I would like to sort the entire matrix by column two, i.e. data[,2] I looked at the help page for sort() but c

Re: [R] Sorting a matrix by a column

2008-08-04 Thread Prof Brian Ripley
On Mon, 4 Aug 2008, John Sorkin wrote: R 2.6 Windows XP I have a 100x4 matirx data<-matrix(nrow=100,ncol=4) I would like to sort the entire matrix by column two, i.e. data[,2] I looked at the help page for sort() but can not determine how I can use it to sort a matrix on one of the matrix's

[R] Sorting a matrix by a column

2008-08-04 Thread John Sorkin
R 2.6 Windows XP I have a 100x4 matirx data<-matrix(nrow=100,ncol=4) I would like to sort the entire matrix by column two, i.e. data[,2] I looked at the help page for sort() but can not determine how I can use it to sort a matrix on one of the matrix's columns. Thanks, John John David Sorkin

Re: [R] Sorting a matrix

2008-07-10 Thread Bert Gunter
D] On Behalf Of Angelo Scozzarella Sent: Thursday, July 10, 2008 11:21 AM To: r-help@r-project.org Subject: [R] Sorting a matrix Hi, I want to sort a matrix by a specific variable without changing the row binding between variables. Ex. NameSex Age FredM

Re: [R] Sorting a matrix

2008-07-10 Thread Jorge Ivan Velez
Dear Angelo, What about this? mydata=read.table(textConnection("NameSex Age FredM 24 JohnM 18 MaryF 21"), header=TRUE,sep="") mydata[order(mydata$Age),] HTH, Jorge On Thu, Jul 10, 2008 at 2:21 PM, Angelo Scozzarella < [EMA

Re: [R] Sorting a matrix

2008-07-10 Thread Erik Iverson
Do you really want to sort a *matrix*, or do you mean a data.frame? See ?order. Angelo Scozzarella wrote: Hi, I want to sort a matrix by a specific variable without changing the row binding between variables. Ex. NameSexAge FredM24 JohnM18 MaryF

[R] Sorting a matrix

2008-07-10 Thread Angelo Scozzarella
Hi, I want to sort a matrix by a specific variable without changing the row binding between variables. Ex. NameSex Age FredM 24 JohnM 18 MaryF 21 ordered by Age NameSex Age JohnM 18 Ma