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
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help