0

Just a question about a neat way to name the result matrix of a foreach loop. This works, but it's a bit verbose, I wonder if there is a simpler method:

r = foreach( i=seq(5), .combine=rbind, .final=function(res) { colnames(res) = c("First", "Second"); return(res) } ) %dopar% { c(i, i+1) }
4

1 回答 1

2

将列名放在您的 RHS 中%dopar%

foreach(i=seq(5), .combine=rbind) %dopar% { c(First=i, Second=i+1) }
于 2015-04-01T18:47:58.990 回答