r - “x”和“y”长度不同
问题描述
我正在尝试确定最佳集群数量。
# Determine optimal number of clusters
wss<-rep(0,2)
wss[1]<-sum(scale(price[,2:2],scale=FALSE)^2)
for(i in 2:16)
wss[i]<-sum(kmeans(price[,2:2],centers=i)$withinss)
plot(4:2,wss,type="b",xlab="Number of clusters",ylab="Within-cluster sum of squares")
除最后一行外,每一行都有效。最后一个给出错误:
xy.coords(x, y, xlabel, ylabel, log) 中的错误:“x”和“y”长度不同
我已经尝试了其他问题的一些解决方案,但没有运气。有什么建议吗?非常感谢!
样本数据:
Country Price
Albania 1.57
Andorra 1.24
Azerbaijan 0.47
Austria 1.33
Belarus 0.73
Belgium 1.54
Bosnia & Herz. 1.29
Bulgaria 1.13
Croatia 1.44
Czech Rep. 1.32
Cyprus 1.28
Denmark 1.74
Estonia 1.41
Finland 1.61
France 1.67
Georgia 0.9
解决方案
wss(y 变量)的长度为 16,但在 x 轴上您使用的是 4:2(长度为 3)。这就是您收到错误的原因。
将 4:2 更改为 17:2 以使 x 和 y 变量的长度相同。喜欢:
plot(17:2,wss,type="b",xlab="Number of clusters",ylab="Within-cluster sum of squares")
推荐阅读
- r - 列表中带有代码的可折叠部分 R Markdown
- javascript - 绕过日志 .js 文件
- python - 从python中的txt文件中提取特定数据
- ios - UIProgressView 圆角半径无法正常工作
- reactjs - FetchMore : 请求每次执行两次
- javascript - 为什么 webpack 5 bundle 包含箭头函数等非 typescript 目标特性?
- c - 在没有 setjmp 的 c 中编写一个更快的协程
- java - 通知自定义声音不适用于某些设备
- java - getContentResolver().delete(uri,null,null) 给出一个错误,即使官方文档说它不应该
- git - 解决 rebase/merge 中的单个 git 文件冲突采取他们的/采取我们的?