在多列中计算R中大于0的值的数量 [英] counting the number of values greater than 0 in R in multiple columns

查看:871
本文介绍了在多列中计算R中大于0的值的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R中有一个数据集myDF,其中包含变量L1,L2,L3,L4。如何获得L2,L3和L4中大于0的区域的观察数?

I have a dataset myDF in R with a the variables L1,L2,L3,L4. How can I get the number of observations in L2, L3, and L4 that area greater than 0?

我想使用子集函数,但我不是确定如何
谢谢!

I would like to use the subset function, I'm just not sure how Thanks!

L1     L2     L3    L4
1       1     0     2
2       1     4     1 
3       1     3     1
2       2     1     1

我希望能够创建一个函数就能统计L2,L3和L4列中大于0的行数。

I would like to be able to create a function that would be able to tally up the number of rows in columns L2, L3, and L4 greater than 0.

推荐答案

colSums(myDF[c("L2", "L3", "L4")] > 0)

这篇关于在多列中计算R中大于0的值的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆