scale_mat_inplace {lowmemtkmeans} | R Documentation |
Rescales a matrix in place.
Description
Recales matrix so that each column has a mean of 0 and a standard deviation of 1. The original matrix is overwritten in place. The function returns the means and standard deviations of each column used to rescale it.
Usage
scale_mat_inplace(M)
Arguments
M |
matrix of data (n x m) |
Details
The key advantage of this method is that it can be applied to very large matrices without having to make a second copy in memory and the orginal can still be restored using the saved information.
Value
Returns a matrix of size (2 x m). The first row contains the column means. The second row contains the column standard dveiations. NOTE: The original matrix, M, is overwritten.
Examples
m = matrix(rnorm(24, 1, 2),4, 6)
scale_params = scale_mat_inplace(m)
sweep(sweep(m,2,scale_params[2,],'*'),2,scale_params [1,], '+') # orginal matrix restored
[Package lowmemtkmeans version 0.1.2 Index]