简体   繁体   English

我有一个子集,我试图从特定行中提取值以便在“R”中使用分位数

[英]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.

相关问题 R。 我正在尝试将我的数据框子集几十年。 因此,我想通过使用列的值进行子集化 - R. I am trying to subset my data frame by decades. Therefore I want to subset by using values of a column 我如何只使用一行来获取“R”中该特定行的分位数 - How would I only work with one row to get quantiles of that specific row in "R" 我正在尝试从R中的findAssoc提取单词和相关性 - I am trying to extract the word and correlation from findAssoc in R 如果我有该行的特定 ID,R 中是否有函数可以输出数据帧的一行中的所有值 - Are there functions in R that can output all the values in a row, of a data frame, if I have a specific ID from that row str_extract// 从以以下内容开头的特定行:“更多”=字符串名称,我有一组数字需要提取,但我遇到了麻烦, - str_extract// from a specific row that starts with: "More" =string name ,I have a set of numbers I need to extract and I am having trouble, 我试图回忆如何从选择特定行的数据框中进行子集化,同时将列名称保留在 R 中 - I am attempting to recall how to subset from a dataframe selecting specific rows while keeping the Column names in R 我试图从 R 中的一行中删除 NA 值,但得到“替换有 863 行,数据有 940” - I am trying to remove NA values from a row in R but getting "replacement has 863 rows, data has 940" 嗨,我正在尝试在 R 中创建一个对象,然后对数据进行子集化,但收到有关维度的错误消息 - Hi, I am trying to create an object in R and then subset the data but am getting an error message regarding dimensions 为R中的列计算分位数到子集 - Computing Quantiles for a column in R to subset 嗨,我是 r 的新手,并试图在 r 中使用 grad - Hi I am new in r and trying to use grad in r
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM