r语言 - 在单因素方差分析中去除数据表中的NA



我目前正在为学校做一个项目,我需要对每个州按地区划分的未投保驾驶者的百分比进行单向方差分析。我正试图从表中删除NA,但遇到了麻烦。

 > motor
 MW   NE   SE    W
 1  0.11 0.09 0.25 0.16
 2  0.13 0.11 0.20 0.16
 3  0.12 0.04 0.13 0.22
 4  0.10 0.07 0.10 0.32
 5  0.09 0.09 0.08 0.10
 6  0.13 0.15 0.16 0.08
 7  0.12 0.07 0.25 0.09
 8  0.13 0.09 0.06 0.15
 9  0.07 0.11 0.28 0.30
 10 0.07 0.09 0.18 0.12
 11 0.13   NA 0.12 0.09
 12 0.17   NA 0.21 0.15
 13 0.06   NA   NA 0.07
 14 0.18   NA   NA   NA
 15 0.08   NA   NA   NA
 16 0.11   NA   NA   NA
 > aov(motor)
 Error in terms.default(formula, "Error") : 
   no terms component nor attribute

我试过用na。省略,完成。case和na。但是我的部分数据被删除,或者我收到了相同的错误消息。我也试过

summary(lm(motor))

这给了我一个p值为0.77,这与我在excel中运行数据时收到的p值(p = 0.007859928)不同

我知道我只是漏掉了一些小东西,但是我已经找了两个小时了,但是一无所获。

有人能帮忙吗?

你的公式不是很好,你需要有一个列作为因子(例如驾驶者)和绘图。您的数据中缺少这一列。假设您包含这个列"motorist"

motorist<-c("A","B","C","B","B","B","B","A","A","A","A","C","C","A","B","C")
motor<-cbind(motorist,motor)
aov(w~motorist,motor) 

最新更新