[R语言计数符合条件的数据帧的行数

问题描述 投票:0回答:2

我有一个具有身高和体重的数据框人口

    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))
r
2个回答
0
投票
您可以按照以下步骤进行:

sum(population$Height > 1.70 & population$Weight > 60)


0
投票
带基数R:

nrow(population[population$Height > 1.70 & population$Weight > 60, ])

使用dpylr:

library(dpylr) library(magrittr) population %>% filter(Height > 1.70 & Weight > 60) %>% nrow()

© www.soinside.com 2019 - 2024. All rights reserved.