Reputation: 301
I've converted a data frame to a sparse matrix to avoid memory issues and save space, once the original data doesn't fit in the memory.
Now, I need to convert this sparse matrix to a realratingmatrix so I can build a recommender with recommenderlab, but i got the following error:
Error in as(aux_max, "realRatingMatrix") :
no method or default for coercing “dgCMatrix” to “realRatingMatrix”
My sample code is the following:
library(Matrix)
UserID<-c(10090,10090,10090,10316,10316)
MovieID <-c(63155,63530,63544,63155,63545)
Rating <-c(2,2,1,2,1)
trainingData<-data.frame(UserIDa,MovieID,Rating)
UIMatrix <- sparseMatrix(i = as.integer(as.factor(trainingData$UserID)),
j = as.integer(as.factor(trainingData$MovieID)),
x = trainingData$Rating
)
dimnames(UIMatrix) <- list(sort(unique(trainingData$UserID)),
sort(unique(trainingData$MovieID)))
rrm <- as(UIMatrix, "realRatingMatrix")
Can anyone give some advise on how to solve that?
Upvotes: 2
Views: 5590
Reputation: 11
I just received this error (no method or default for coercing “matrix” to “realRatingMatrix”), I needed to install library(recommenderlab) package.
Upvotes: 1
Reputation: 301
Well, I think I got the answer. I coerced the "dgCMatrix" to "matrix" and then to "realratingmatrix". Seems to work fine.
rrm<- as( as(UIMatrix, "matrix") , "realRatingMatrix")
Upvotes: 3