Guest User

Untitled

a guest
Nov 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. library(Matrix)
  2. set.seed(1)
  3. mat <- Matrix(0,5,5)
  4.  
  5. idx.mat <- do.call(rbind,lapply(1:5,function(i) sample(1:5,3,replace=F)))
  6. val.mat <- matrix(runif(15,1,10),5,3)
  7.  
  8. mat <- do.call(rbind,lapply(1:nrow(mat),function(i) {
  9. mat[i,idx.mat[i,]] <- val.mat[i,]
  10. return(mat[i,])
  11. }))
Add Comment
Please, Sign In to add comment