I have a matrix of n*m dimension. I wanted to count the number of columns in a row which has a value greater than "X". How to do this in R? Please let me know.
m1 > X will create a TRUE/FALSE logical matrix. Since TRUE values are treated as 1 and FALSE values are treated as 0, rowSums(m1 > X) will give you a count for each row of the number of values in that row that is greater than X.
You can try
rowSums
explanation
m1 > X
will create aTRUE
/FALSE
logical matrix. SinceTRUE
values are treated as1
andFALSE
values are treated as0
,rowSums(m1 > X)
will give you a count for each row of the number of values in that row that is greater thanX
.data