2

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 convertmat3 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'
Ignacio
  • 7,646
  • 16
  • 60
  • 113

1 Answers1

2

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().

F. Privé
  • 11,423
  • 2
  • 27
  • 78