[R] error in my previous message

markleeds at verizon.net markleeds at verizon.net
Wed Feb 11 07:23:10 CET 2009


i'm sorry. i had an error in my previous code because i left out a 
letter in the rownames.
while fixing that, i also found a solution. so i'm sorry for the 
confusion.

below is my fix.

temp2 <- matrix(rnorm(10),nc=1,nrow=10)
rownames(temp2) <- c("a","b","c","d","e","f","g","h","i","j")
print(temp2)
temp2 <- as.matrix(temp2[order(temp2[,1,drop=FALSE]),])
print(temp2)





On Wed, Feb 11, 2009 at  1:18 AM, markleeds at verizon.net wrote:

> 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 in a few different places with 
> no success. Thanks.
>
> temp1 <- matrix(rnorm(10),nc=2,nrow=5)
> rownames(temp1) <- c("a","b","c","d","e")
> print(temp2)
> temp1 <- temp1[order(temp1[,1]),]
> print(temp1)
>
> temp2 <- matrix(rnorm(10),nc=1,nrow=5)
> rownames(temp2) <- c("a","b","c","d","e","f","g","h","i")
> print(temp2)
> temp2 <- temp2[order(temp2[,1]),]   # PROBLEM IS HERE
> print(temp2)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list