data.table - Recoding of huge matrix in R -
I have a huge matrix with values of 1, 2 or 3 (and some NA) values. If the matrix is N xm then i have to pay attention to the N x 3m with each value of the original matrix according to the 3 entries of the new matrix. If the value is x in the matrix of the matrix then the numerator entry is 1 and the other two will be zero (if na all the other zeros).
1, 3, NA, 1
to
0 0 0 0 0 0 0 1 0 0
Ie
1 = 1 0 0 3 = 0 0 1 NA = 0 0 0 1 = 1 0 0
I have to do this efficiently in R because matrix is very big. What is the most effective way to do this? The matrix is in a data.table
with pre-assigned empty matrix.
mat
You can use this method from the matrix < Code> matrix package.
Library (matrix) NewMate & lt; - Matrix (0, nucleus = nacelle (mat) * 3, nero = no (mat), spurs = tru) newmate [ind [complete cases (ind),]]
The use of sparse matrix involves much less memory usage.
Comments
Post a Comment