Skip to content

convert a matrix to binaryMatrix in Recommenderlab

2 messages · Jing Xi, Michael Hahsler

11 days later
#
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