Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能';我在r中的for循环代码中找不到错误_R_Loops - Fatal编程技术网

我能';我在r中的for循环代码中找不到错误

我能';我在r中的for循环代码中找不到错误,r,loops,R,Loops,我有以下代码: test_x <- 2000 #functions used: `%+<-%` = function(e1,e2) eval.parent(substitute(e1 <- e1 + e2)) CreateData <- function() { numeric(test_x) } #variables test_sum <- 0 test_q <- 0 test_q <- CreateData() test_Q <- 0

我有以下代码:

test_x <- 2000

#functions used:

`%+<-%` = function(e1,e2) eval.parent(substitute(e1 <- e1 + e2))

CreateData <- function()
{
numeric(test_x)
}

#variables

test_sum <- 0
test_q <- 0
test_q <- CreateData()
test_Q <- 0
test_Q <- CreateData()
test_step <- 0.01

#two for loops

for (i in test_x) {
  test_q[i] <- 40
}
for (i in (test_x - 1):0) {
  test_sum %+<-% (test_q[i]*test_step)
  test_Q[i] <- test_sum
}

test_x在第一个循环中
i
仅取值2000,那么您应该修改第一个循环,如下所示:

for (i in 1:test_x) {
  test_q[i] <- 40
}
for(1中的i:test_x){

test_q[i]您正在为(test_x中的i)
,但是
x_test=2000
所以您只为(2000中的i)做
所以
i
将只取
2000
,您必须为(i in 1:test_x)做
你完全正确。我不确定我怎么看不到。如果你将其作为解决方案发布,我会将其标记为已解决。