Next with Revolution R's foreach package?

前端 未结 2 821
灰色年华
灰色年华 2021-02-07 04:09

I\'ve looked through much of the documentation and done a fair amount of Googling, but can\'t find an answer to the following question: Is there a way to induce \'next-like\' fu

2条回答
  •  梦毁少年i
    2021-02-07 04:32

    You could put your code in a function and call return. It's not clear from your example what you want it to do when n %% 3 so I'll return NA.

    funi <- function(i) {
      n <- i + floor(runif(1, 0, 9))
      if (n %% 3) return(NA)
      n
    }
    foreach(i = 1:10, .combine = "c") %dopar% { funi(i) }
    

提交回复
热议问题