[英]How to calculate proportion in R Programming
您可以使用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.