[R] select subrows based on a specific column in a matrix

Seungyeul Yoo seungyeul.yoo at me.com
Thu Jun 7 18:07:51 CEST 2012


Hi all,

I have a matrix with 10000 rows and 10 columns. The last columns contains another identifiers but the values are not uniques so that I want to generate another matrix with rows with unique values in the last column.

If I did

tmp<-unique(my_mat$col10) 

this will give me 8560 unique entries so the ideal matrix will be 8560X10 columns now then. 

I tried

sub_mat<-my_mat[tmp,]

but it generated weird results with many "NA" values and the order was not changed. The original matrix was ranked from top so I don't want to lose the order too.

For the similar problem, I have used "match" function and do some manipulate to identify the index of the first appearance of each value but is there any better and neat way to achieve the same function?

Thanks,

Seungyeul Yoo

Postdoc Fellow,
Institute of Genomics and Multiscale Biology
Department of Genetics and Genomic Sciences
Mount Sinai School of Medicine



More information about the R-help mailing list