R程序设计-循环的并行处理
我有一个大约1000列/参数的数据集,希望在每个参数之间执行回归。因此,第1列中的数据将与所有其他999个参数进行线性回归等叠加 该方法的非优化版本为: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 <
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()
文档,但如果您有任何建议,请分享。