r - 如何在 R 编程中计算比例
解决方案
您可以使用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
推荐阅读
- javascript - 有没有办法使用字符串为对象的深层嵌套属性赋值?
- c# - 订阅方法执行c#
- java - GXT 如何在 XTemplate 中显示树对象?
- spring - 可以使用 Intellij Scratch 文件通过 JpaRepository 接口进行查询吗?
- jquery - 如何在不使用scrollY的情况下垂直修复数据表标题?
- r - 在 data.tables 中创建新列时如何使用向量化的 get() 函数?
- python - TypeError: "'int' object is not callable", '发生在索引 0'
- hybris - 登录用户时出现 StackOverflowError,该用户应该在 Backoffice 资源管理器树中查看特定节点
- typescript - 在组件上使用 v-for 的反应式列表
- git - Katalon Studio 和 Git SubModules:如何将外部公共库导入到 katalon 项目中