[英]R language count rows of dataframe matching a criteria
我有一个身高和体重的数据框人口
Height Weight
1 1.4349813 53.73766
2 1.6875582 61.83858
3 1.4952729 51.64203
etc....
我怎么能算出这些人中有多少身高高于1.70,体重高于60?
I tried nrow(which(population$Height > 1.70 && population$Weight > 60))
您可以按照以下步骤进行:
sum(population$Height > 1.70 & population$Weight > 60)
使用基础 R:
nrow(population[population$Height > 1.70 & population$Weight > 60, ])
使用 dpylr:
library(dpylr)
population %>% filter(Height > 1.70 & Weight > 60) %>% nrow()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.