Count number of columns by a condition (>) for each row

后端 未结 4 480
小蘑菇
小蘑菇 2020-11-27 19:37

I am trying to work out for each row of a matrix how many columns have values greater than a specified value. I am sorry that I am asking this simple question but I wasn\'t

4条回答
  •  一生所求
    2020-11-27 20:07

    We can also do with Reduce and + (assuming there are no NA elements)

     Reduce(`+`, lapply(as.data.frame(data), `>`, 30))
    

    This should be efficient as we are not converting to a matrix.

提交回复
热议问题