简体   繁体   中英

Convert bigstatsr::FBM to matrix?

Is is possible to convert an bigstatsr::FBM object to a regular R matrix?

For example, suppose that I generate the following matrix:

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)

I want to convert mat3 to a regular R matrix object. I tried the following but it did not work

A <- as.matrix(mat3)
Error in as.vector(x, mode) : 
  cannot coerce type 'environment' to vector of type 'any'

You can just use mat3[] to get a matrix from an FBM.

Please have a look at https://privefl.github.io/R-presentation/bigstatsr.html#7 .

To do the opposite, you can use as_FBM() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM