[英]FBM() of bigstatsr does not calculate the matrix correctly while using parallel foreach as it does when the code is running in a simple for loop
[英]Convert bigstatsr::FBM to matrix?
是否可以将bigstatsr::FBM
对象转换为常规 R 矩阵?
例如,假设我生成以下矩阵:
N <- 100
K <- 50
`%dopar%` <- foreach::`%dopar%`
`%:%` <- foreach::`%:%`
mat3 <- bigstatsr::FBM(N, K)
cl <- parallel::makeCluster(2)
doParallel::registerDoParallel(cl)
tmp3 <- foreach::foreach(j = 1:K, .combine = 'c') %:%
foreach::foreach(i = 1:N, .combine = 'c') %dopar% {
mat3[i, j] <- i + j
NULL
}
parallel::stopCluster(cl)
我想将mat3
转换为常规的 R 矩阵对象。 我尝试了以下但没有用
A <- as.matrix(mat3)
Error in as.vector(x, mode) :
cannot coerce type 'environment' to vector of type 'any'
您可以使用mat3[]
从 FBM 获取矩阵。
请查看https://privefl.github.io/R-presentation/bigstatsr.html#7 。
相反,您可以使用as_FBM()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.