[英]I have a subset and I am trying to extract values from a specific row in order to use quantiles in "R"
The subset has many values different rows but for my purpose, I only use one该子集有许多不同行的值,但出于我的目的,我只使用一个
Current Code当前代码
male <- subset(dropped, SEXP == 2)
female <- subset(dropped, SEXP == 1)
incomeMale <- subset(male, TOTINCP > 0)
#a vector called percentIncome of all the values in the row TOTINCP from incomeMale
quantile(percentIncome, 0.05,0.10,0.95,0.90)
I want a vector of all the values in TOTINCP so that I can use the quantiles function to get the percentages of the bottom 5%, 10% and top 5%, 10%.我想要一个 TOTINCP 中所有值的向量,以便我可以使用分位数 function 来获得底部 5%、10% 和顶部 5%、10% 的百分比。 I tried using nrows() but it doesn't take in the subset of incomeMale so it would just be giving me all the values in TOTINCP.我尝试使用 nrows() 但它不包含incomeMale 的子集,所以它只会给我 TOTINCP 中的所有值。
It's difficult to understand exactly what you're looking for without a reproducible example, but here's an outline of how to do something similar with the iris data set:如果没有可重现的示例,很难准确理解您要查找的内容,但这里概述了如何对 iris 数据集执行类似操作:
#Using the iris data set, limit to one species
subset(iris, Species == "virginica")
#Get a vector of the Sepal Width for one species
subset(iris, Species == "virginica")$Sepal.Width
#Get quantiles for the Sepal Width for one species
quantile(subset(iris, Species == "virginica")$Sepal.Width, c(0.05, 0.1, 0.9, 0.95))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.