[英]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.