这个R代码:
avector <- as.vector(top.links.added.overall$Amount)
x <- as.vector(top.links.added.overall[order(avector),])
x$Amount <- factor(x$Amount)
x$color[x$Amount == 100] <- "red"
x$color[x$Amount == 500] <- "blue"
x$color[x$Amount == 1000] <- "darkgreen"
dotchart(x$Amount,
labels = row.names(x),
cex=.7,
groups = x$Amount,
gcolor = "black",
color = x$color,
pch=19,
main = "Gas Mileage for Car Models\ngrouped by cylinder",
xlab = "Miles Per Gallon")
返回此错误:
Error in dotchart(x$Amount, labels = row.names(x), cex = 0.7, groups = x$Amount, :
'x' must be a numeric vector or matrix
这是top.links.added.overall的数据文件:
Amount,Name
1000,Google
500,Cnn
100,Yahoo
'x'是一个向量,那是什么导致了这个错误?
答案 0 :(得分:2)
删除转换为因子x$Amount <- factor(x$Amount)
dotchart(x$Amount,
labels = row.names(x),
cex=.7,
groups = factor(x$Amount),
gcolor = "black",
color = x$color,
pch=19,
main = "Gas Mileage for Car Models\ngrouped by cylinder",
xlab = "Miles Per Gallon")
可能会对你有帮助。