R session abort during data.matrix transformation -




i have big binary data.table:

> str(mat) classes 'data.table' , 'data.frame':  262561 obs. of  10615 variables:  $ 1001682: num  0 0 0 0 0 0 0 0 0 0 ...  $ 1001990: num  0 0 0 0 0 0 0 0 0 0 ...  $ 1002541: num  0 0 0 0 0 0 0 0 0 0 ...  $ 1002790: num  0 0 0 0 0 0 0 0 0 0 ...  $ 1003312: num  0 0 0 0 0 0 0 0 0 0 ...  $ 1004403: num  0 0 0 0 0 0 0 0 0 0 ... 

there somewhere 1 (it's not full of zeros). , i'm trying convert data.matrix writing mat <- data.matrix(mat) r session abort. problem computer? should try high performance computer? or there other way this? need in data.matrix.

i'm using macbook pro 2015 2.7 ghz intel core i5 , 8gm ddr3.

i not sure if more efficient roland's method, produces same matrix , not require reshape of data. require same lapply in my previous answer op, described slow. using data.table constructed in roland's answer.

library(matrix)  # positions of non-zero values in data.table myrows <- lapply(dt, function(x) which(x != 0))  # build sparse matrix dt <- sparsematrix(i = unlist(myrows), # row positions of non 0 values                    j = rep(seq_along(myrows), lengths(myrows)), # column positions                    dims = c(nrow(dt), ncol(dt))) # dimension of matrix 

this returns

dt 3 x 5 sparse matrix of class "lgcmatrix"  [1,] . | . | . [2,] | . . . . [3,] | | | . | 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -