本文主要是介绍Error in *** : replacement has length zero,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Error in *** : replacement has length zero
目录
Error in *** : replacement has length zero
问题:
解决:
完整问题:
问题:
会出现:data[1] * data[0]
但是R的索引是从1开始的,你说data[0]是什么意思?
data = c(1, 4, 5, 5, 7, 9, 12, 14, 15, 17)for (i in 1:length(data)) {data[i] = data[i] * data[i-1]
}
解决:
#解决出现索引0 的问题
for (i in 2:length(data)) {data[i] = data[i] * data[i-1]
}#view updated vector
data
完整问题:
> data = c(1, 4, 5, 5, 7, 9, 12, 14, 15, 17)
>
>
> for (i in 1:length(data)) {
+ data[i] = data[i] * data[i-1]
+ }
Error in data[i] <- data[i] * data[i - 1] : replacement has length zero
>
这篇关于Error in *** : replacement has length zero的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!