【发布时间】:2020-02-02 02:09:48
【问题描述】:
每次我尝试计算这一行“DHS
setwd("~/Google Drive/R Data")
data <- read.csv('cps92_08.csv')
year <- data$year
year1992 <- subset(data,year<2000)
year2008 <- subset(data,year>2000)
ahe1992 <- (year1992$ahe)
ahe2008 <- (year2008$ahe)
max(ahe1992)
min(ahe1992)
mean(ahe1992)
median(ahe1992)
sd(ahe1992)
max(ahe2008)
min(ahe2008)
mean(ahe2008)
median(ahe2008)
sd(ahe2008)
adjahe <- ahe1992*(215.2/140.3)
max(adjahe)
min(adjahe)
mean(adjahe)
median(adjahe)
sd(adjahe)
D <- mean(ahe2008) - mean(adjahe)
education <- data$bachelor
ahebachelors1992 <- subset(adjahe, education>0)
ahehighschool1992 <- subset(adjahe,education<1)
ahebachelors2008 <- subset(ahe2008,education>0)
ahehighschool2008 <- subset(ahe2008,education<1)
DHS <- mean(ahebachelors2008) - mean(ahebachelors1992)
【问题讨论】:
-
ahebachelors2008中有什么内容?里面有NA吗?运行which(is.na(ahebachelors2008))?或者可能什么都没有? -
您的数据框中可能有 NA,您应该在计算
mean时使用参数na.rm = TRUE。检查文档?mean() -
请让这个问题可重现。这包括样本明确数据(例如,
dput(head(x))或data.frame(x=...,y=...))和预期输出。参考:stackoverflow.com/questions/5963269、stackoverflow.com/help/mcve 和 stackoverflow.com/tags/r/info。 -
in ahebachelors2008 是 2008 年计算具有学士学位的人的平均小时收入的数据。如果我没有正确回答您的问题,我很抱歉,我两周前才开始使用 R,所以这对我来说太新鲜了!有什么我可以与您分享的信息可以帮助您更好地帮助我吗?我运行了函数 which(is.na(ahehbachelors2008)) 那里有 6594 个数据点。
-
好吧,所以我刚刚检查了整个 ahbachelors 2008 并注意到在 6594 个数据点中,有 2953 个带有数字 --- 其余的都包含 NA。我将如何解决这个问题?
标签: r