m <- matrix(sample(c(NA,0:5),50, replace=TRUE, prob=c(.5,rep(.5/6,6))),
nrow=5, ncol=10, dimnames = list(users=paste('u', 1:5, sep=''),
items=paste('i', 1:10, sep='')))
m
## drop all NAs in the representation. Zeros are represented by very small values.
sparse <- dropNA(m)
sparse
## convert back to matrix
dropNA2matrix(sparse)
## Note: be careful with the sparse representation!
## Do not use is.na, but use
dropNAis.na(sparse)
Run the code above in your browser using DataLab