Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.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
Arrays 在R中的数组中存储多维数据_Arrays_R - Fatal编程技术网

Arrays 在R中的数组中存储多维数据

Arrays 在R中的数组中存储多维数据,arrays,r,Arrays,R,在R中,我使用以下代码对几个因变量运行自变量的滚动回归: P <- nrow(Returns)-20 coefi <- vector('list',P) for(i in 0:(P-1)){ stepfit <- regsubsets(Dependent1~.,data=Returns[(1+i):(20+i),],method="backward") coefi[[i+1]] <- coef(stepfit,id=which.max(st

在R中,我使用以下代码对几个因变量运行自变量的滚动回归:

P <- nrow(Returns)-20
coefi <- vector('list',P)

for(i in 0:(P-1)){

  stepfit <- regsubsets(Dependent1~.,data=Returns[(1+i):(20+i),],method="backward")
  coefi[[i+1]] <- coef(stepfit,id=which.max(stepfit.summary$adjr2))

   }

你能发布你的数据的子集吗?这可能更容易。另外,如果您想在三个因变量之间应用它,为什么不运行三次循环呢?这不是一个很有规模的答案,但能完成任务。另一种方法是用它创建一个函数,然后将因变量作为参数传递。@PatrickWilliams,谢谢您的回答。我发布了一个子集,希望对您有所帮助。我的实际集合包括相当多的3个以上的依赖项,我应该更清楚,这就是为什么我想在列之间有一个循环。你对R足够精通,可以编写一个函数吗?如果您这样做,那么您可以
在您的列中应用您的函数。谢谢您的建议!我刚刚开始学习。我想它的形式是:myfunction
Dependent 1 Dependent 2 Independent 1   Independent 2   Independent 3   Independent 4   Independent 5

1/31/2008   3.28%   -2.13%  -0.27%  0.09%   -0.03%  -0.28%  3.86%

2/29/2008   0.83%   1.81%   0.52%   -0.40%  1.53%   0.48%   -0.54%

3/31/2008   1.12%   -0.55%  -0.75%  -0.46%  1.48%   0.25%   4.86%

4/30/2008   -2.30%  2.21%   0.36%   -0.92%  1.43%   2.67%   0.31%

5/31/2008   -0.56%  -0.21%  0.85%   1.21%   -0.32%  0.63%   2.75%

6/30/2008   1.98%   -1.99%  -0.33%  1.27%   0.07%   -3.02%  9.04%

7/31/2008   -0.79%  -4.69%  0.17%   -0.76%  0.88%   -1.61%  5.86%

8/31/2008   0.01%   2.27%   -0.37%  3.89%   -0.43%  -1.01%  -5.60%

9/30/2008   3.85%   1.83%   3.28%   -2.28%  -2.69%  -0.42%  1.88%

10/31/2008  7.49%   3.79%   3.86%   -3.17%  0.45%   3.25%   6.14%

11/30/2008  0.76%   1.11%   -0.54%  -0.36%  4.74%   4.14%   25.68%

12/31/2008  -0.27%  -1.53%  4.86%   0.07%   1.26%   0.50%   10.00%

1/31/2009   1.20%   1.38%   0.31%   -0.31%  -1.72%  1.91%   3.81%

2/28/2009   1.65%   -2.07%  2.75%   0.28%   1.92%   -0.78%  1.85%

3/31/2009   -2.10%  0.86%   9.04%   0.71%   0.09%   2.09%   1.91%

4/30/2009   -3.07%  5.22%   5.86%   3.65%   -0.40%  1.65%   2.07%

5/31/2009   -0.41%  13.76%  -5.60%  1.65%   -0.46%  1.21%   -1.34%

6/30/2009   0.25%   3.11%   1.88%   2.28%   -0.92%  -1.84%  3.59%

7/31/2009   2.67%   -1.87%  6.14%   3.24%   1.21%   0.02%   0.60%

8/31/2009   0.63%   4.81%   -0.27%  2.61%   1.27%   -2.07%  4.29%

9/30/2009   -3.02%  4.78%   3.66%   0.88%   -0.76%  -0.32%  1.86%

10/31/2009  -1.61%  1.65%   0.55%   1.55%   3.89%   -1.04%  -0.95%

11/30/2009  -1.01%  1.60%   0.60%   1.19%   -2.28%  0.41%   2.13%

12/31/2009  -0.42%  2.89%   0.28%   -1.62%  1.49%   0.84%   2.72%