I have a data frame Likes for n users and m likes, with userid and likeid1 : likeidm as my variables. The specific userids are stored in column 1 (Likes$userid) and the cells contain 1 or 0 depending on wether the user liked the page with the respective likeid or not.
library(Matrix)
Likes <- data.frame(userid=c("n1","n2"),
m1=c(0,1),
m2=c(0,0),
m3=c(0,0),
m4=c(1,0)
)
Likes [1,1:5]
userid m1 m2 m3 m4
1 n1 0 0 0 1
Now, I want to create a sparse matrix. How would I specify j in the following code? I know it is not right the way I did it, since technically like ids are not in a column but already specified as variables in my data frame.
sM_Likes <- sparseMatrix(Likes, i=likes$userid, j=1,c(2:ncol(Likes)), x=1)
Thanks in advance (and please apologize the very basic question).