Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(Matrix)
- set.seed(1)
- mat <- Matrix(0,5,5)
- idx.mat <- do.call(rbind,lapply(1:5,function(i) sample(1:5,3,replace=F)))
- val.mat <- matrix(runif(15,1,10),5,3)
- mat <- do.call(rbind,lapply(1:nrow(mat),function(i) {
- mat[i,idx.mat[i,]] <- val.mat[i,]
- return(mat[i,])
- }))
Add Comment
Please, Sign In to add comment