如何计算R编程中的比例

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

This is my data set

问题是如何计算数据集中150个高度的男性比例?

r
1个回答
0
投票

您可以使用subset根据条件过滤数据,然后计算两个数据帧(原始数据帧和已过滤数据帧)的长度比。

weight <- c(76,69,64,62,62,57,55,62,60,55)
height <- c(167,167,168,168,168,168,168,168,149,140)
data.foo <- cbind(weight, height) # Example dataset with only height and weight columns

over.150 <- subset(data.foo, height > 150) # filtered data
proportion <- nrow(over.150)/nrow(data.foo)

比例

[1] 0.8

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