R中的条件和 [英] Conditional Sum in R

查看:73
本文介绍了R中的条件和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个200行乘6列的数据框。我对计算Col A中的值小于特定数字的总次数感兴趣。该数字可以硬编码。我不知道从哪里开始...

I have a data frame that is 200 rows by 6 columns. I am interested in computing the total times that a value in Col A is less than a specific number. The number can be hard coded. I do not know where to begin...

推荐答案

对于稍微复杂的问题,请使用哪来告诉总和的总和:
,如果DF是数据框:

For a slightly more complex problem, use the "which" to tell the "sum" where to sum: if DF is the data frame:

      Ozone Solar.R  Wind Temp Month Day
 1      41     190  7.4   67     5   1
 2      97     267  6.3   92     7   8   
 3      97     272  5.7   92     7   9

例如:求和Solar.R(第2列)的值,其中Column1或Ozone> 30 AND Column 4或Temp> 90

Example: sum the values of Solar.R (Column 2) where Column1 or Ozone>30 AND Column 4 or Temp>90

sum(DF[which(DF[,1]>30 & DF[,4]>90),2])

这篇关于R中的条件和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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