[R] convert a matrix to binaryMatrix in Recommenderlab
Michael Hahsler
mhahsler at lyle.smu.edu
Wed Aug 31 00:54:45 CEST 2011
Hi Jing
recommenderlab is still under heavy development and quite far away from
version 1.0-0. Here is some code to create a binaryRatingMatrix from a
0-1 matrix:
library(recommenderlab)
## create a 10x10 0-1 matrix
m <- matrix(sample(c(0,1),100, replace=TRUE), nrow=10, ncol=10)
m
## coerce it into a binaryRatingMatrix
b <- as(m, "binaryRatingMatrix")
b
## coerce it back to see if it worked
as(b, "matrix")
Hope this helps,
-Michael
--
Dr. Michael Hahsler, Visiting Assistant Professor
Department of Computer Science and Engineering
Lyle School of Engineering
Southern Methodist University, Dallas, Texas
(214) 768-8878 * mhahsler at lyle.smu.edu * http://lyle.smu.edu/~mhahsler
More information about the R-help
mailing list