Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.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来编码这个方程_R - Fatal编程技术网

用R来编码这个方程

用R来编码这个方程,r,R,请帮助,我是R的新手。如何在R程序中使用loop for and while对这个等式进行编码 您可以尝试下面的while循环 x <- c(1, 5, 2) n <- 4 while (n <= 77) { x <- append(x, log10(x[n - 1]) + x[n - 2] + sqrt(x[n - 3])) n <- n + 1 } > x[77] [1] 519.329

请帮助,我是R的新手。如何在R程序中使用loop for and while对这个等式进行编码

您可以尝试下面的while循环

x <- c(1, 5, 2)
n <- 4
while (n <= 77) {
  x <- append(x, log10(x[n - 1]) + x[n - 2] + sqrt(x[n - 3]))
  n <- n + 1
}
> x[77]
[1] 519.329