今天我试着完成我最后的R-study练习,但是我失败了。我不允许你展示我的学术论文的确切说明,但你可以帮助我处理我在采购后收到的警告。它们是什么意思?什么不合适?我知道,这个问题很模糊,但这是唯一的提问方式。我相信是关于"Aufgabe 3“和"Aufgabe 4”的
这是我的输入:
x <- read.csv ("http://hci.stanford.edu/jheer/workshop/data/worldbank/worldbank.csv")
y <- (colnames (x) <- (c ("Country", "Year", "co2", "power","energy", "fertility", "gni", "internet", "life.expectancy","military", "population", "hiv.prevalence")))
y
####Aufgabe 1####
f1 <- min(x$fertility, na.rm=TRUE)
f1
####Aufgabe 2####
f2 <- max (subset(x, Country=="Australia" | Country=="Belarus" | Country=="Germany", select=fertility), na.rm=TRUE)
f2
####Aufgabe 3####
q1 <- quantile (subset(x, Year==2005, select=military), probs=c(.25), na.rm=TRUE)
q1
####Aufgabe 4####
q2 <- quantile (subset(x, Year==2001, select=population), probs=c(.05), na.rm=TRUE)
q2
####Aufgabe 4####
n <- length(which (is.na (subset (x, Year==2000, select=military))))
n
####Aufgabe 5####
library(psych)
mil<- skew (x$military)
coun<- skew(x$Country)
Ye<- skew(x$Year)
co<- skew(x$co2)
po<- skew(x$power)
en<- skew(x$energy)
fer<- skew(x$fertility)
gni<- skew(x$gni)
inertnet<- skew(x$internet)
life<- skew(x$life.expectancy)
pop<- skew(x$population)
hiv<- skew(x$hiv.prevalence)
mil
coun
Ye
co
po
en
fer
gni
inertnet
life
pop
hiv
ku1<- "co2"
ku1...and这些我在采购后得到的警告:
1. In var(as.vector(x), na.rm = na.rm : Na generated through conversion
2. n mean.default(x) : argument is not numeric or logical: returning NA
3. 3: In Ops.factor(x, mx) : - not meaningful for factors
4. In var(as.vector(x), na.rm =na.rm) : Na generated through conversion 发布于 2012-12-22 19:22:29
as.vector(x)操作导致x的一个或多个元素被转换为NA,因为这些组件的转换未定义。mean.default时,x既不是数字也不是逻辑,因此函数不能对数据执行任何操作x和mx都是因子,并且- (和其他数学运算符)没有为因子对象定义。所有这些都指向输入数据的问题,通常是创建了一个因子。
警告来自下面这行:
> coun <- skew(x$Country)
Warning messages:
1: In var(as.vector(x), na.rm = na.rm) : NAs introduced by coercion
2: In mean.default(x) : argument is not numeric or logical: returning NA
3: In Ops.factor(x, mx) : - not meaningful for factors
4: In var(as.vector(x), na.rm = na.rm) : NAs introduced by coercion这是因为x$Country是一个因素:
> str(x)
'data.frame': 1362 obs. of 12 variables:
$ Country : Factor w/ 227 levels "","Afghanistan",..: 19 19 19 19 19 19 166 166 166 166 ...
....即使你把它设为一个字符,你也可以计算这个变量的偏斜度。只需注释掉这一行。
https://stackoverflow.com/questions/14002345
复制相似问题