# Dimensionality reduction (SVD or PCA) on a large, sparse matrix

I have a large, sparse Matrix of features I would like to use in a machine learning algorithm:

library(Matrix)
set.seed(42)
rows <- 500000
cols <- 10000
i <- unlist(lapply(1:rows, function(i) rep(i, sample(1:5,1))))
j <- sample(1:cols, length(i), replace=TRUE)
M <- sparseMatrix(i, j)


Because this matrix has many columns, I would like to reduce it's dimensonality to something more manageable. I can use the excellent irlba package to perform SVD and return the first n principle components (5 shown here; I'll probably use 100 or 500 on my actual dataset):

library(irlba)