Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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_Parallel Processing - Fatal编程技术网

R程序设计-循环的并行处理

R程序设计-循环的并行处理,r,parallel-processing,R,Parallel Processing,我有一个大约1000列/参数的数据集,希望在每个参数之间执行回归。因此,第1列中的数据将与所有其他999个参数进行线性回归等叠加 该方法的非优化版本为: loop <- c(1:ncol(Data)) for ( column in loop ){ # Fetch next data to be compared nextColumn <- column + 1 # Fetch next column while ( nextColumn <

我有一个大约1000列/参数的数据集,希望在每个参数之间执行回归。因此,第1列中的数据将与所有其他999个参数进行线性回归等叠加

该方法的非优化版本为:

loop <- c(1:ncol(Data))
for ( column in loop ){

    # Fetch next data to be compared
    nextColumn <- column + 1

    # Fetch next column
    while ( nextColumn <= ncol(Data) ){   

       # Analysis logic

       # Increment the counter
       nextColumn <- nextColumn + 1

   }
}

loop像这样使用
mappy

X <- 1:(ncol(mtcars)-1)     # first through penultimate column
Y <- 2:ncol(mtcars)         # second through last column
mapply(function(x,y) sum(mtcars[,x],mtcars[,y]), X, Y)

X如果您是R新手,我不会尝试并行化您的代码。在apply()中调用回归函数。看看下面的内容。@JamieMac:谢谢。我很难弄清楚
apply()
如何一次获取两列/参数,执行回归并移动到下一个组合。目前,在分析逻辑中,我还捕获了所有
summary()
数据,因此在回归循环通过不同列/参数时,我有一个不断更新的向量。仍在阅读
apply()
文档,但如果您有任何建议,请分享。