[datatable-help] Selecting rows (rownames) and colnames of a matrix	b
    Peter Kupfer 
    peter.kupfer at me.com
       
    Thu Jan 26 15:49:16 CET 2012
    
    
  
Dear all, 
I am looking for a workaround to select rows and cols of a matrix. 
I want to select all rows which have a value higher than a threshold. 
If i create my matrix with 
m <- matrix(1:12,3,4) 
I get 
     [,1] [,2] [,3] [,4] 
[1,]    1    4    7   10 
[2,]    2    5    8   11 
[3,]    3    6    9   12 
Let's give the matrix rownames  with 
rownames(m) <- c("M1", "M2", "M3") 
I get my matrix 
   [,1] [,2] [,3] [,4] 
M1    1    4    7   10 
M2    2    5    8   11 
M3    3    6    9   12 
No I want to select the rownames of m which have a value higher than 7 in a row 
I tried 
m[apply(m, 1, function(x) any(x > 7)),] 
but the return was the whole matrix. So it was not possible for me to get the two last columns.... 
Is there any easy way to get the index or rowname  of a matrix which have an entry with a chosen threshold? 
Would be nice if anybody can help me out. 
All the best 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120126/2853ebee/attachment.htm>
    
    
More information about the datatable-help
mailing list