mtx <- matrix(NA, 15490 , 15,490)
mtx[ as.matrix(S1) ] <- 1 # two column matrix can be used to index
You will need to have sufficient machine resources if this is your strategy. It's not going to fit inside most 4GB devices, or it may fit but then run out of memory if you try to do anything with it. Filling with NA will not conserve space unless you use sparse matrices from pkg::Matrix. I continue to believe you need statistical advice more than you need coding advice, even though you appear to have deleted an earlier version of this question. I do see this as a sensible way forward to build a classification structure.