[R] how to sort

Allan Engelhardt allane at cybaea.com
Thu Jun 18 08:19:31 CEST 2009


On 18/06/09 04:16, onyourmark wrote:
> Hi. I have an object. I think it is a list.
>    
It is a matrix

corTFandPCA <- runif(922*5)
dim(corTFandPCA) <- c(922,5)
dimnames(corTFandPCA) <- list(paste("abdomen",2:923,sep="."), 
paste("PC",1:5,sep=""))
str(corTFandPCA)
#  num [1:922, 1:5] 0.17 0.285 0.388 0.995 0.211 ...
#  - attr(*, "dimnames")=List of 2
#   ..$ : chr [1:922] "abdomen.2" "abdomen.3" "abdomen.4" "abdomen.5" ...
#   ..$ : chr [1:5] "PC1" "PC2" "PC3" "PC4" ...


> I want to order it according to PC1.
>
> I tried this
>
>   dfCorTFandPCA=as.data.frame(corTFandPCA)
>    
>> orderedCorTFandPCA=dfCorTFandPCA[order(PC1)]
>>      

Try

corTFandPCA[order(corTFandPCA[,"PC1"]),]




More information about the R-help mailing list