Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. > myMatrix
  2. a b c
  3. a . 1 2
  4. b 1 . .
  5. c 2 . .
  6.  
  7. library(Matrix)
  8. myMatrix <- sparseMatrix(
  9. i = c(1,1,2,3),
  10. j = c(2,3,1,1),
  11. x = c(1,2,1,2))
  12.  
  13. myMatrix
  14. # 3 x 3 sparse Matrix of class "dgCMatrix"
  15. #
  16. # [1,] . 1 2
  17. # [2,] 1 . .
  18. # [3,] 2 . .
  19.  
  20. mat.summ <- summary(myMatrix)
  21. lower.summ <- subset(mat.summ, i >= j)
  22.  
  23. sparseMatrix(i = lower.summ$i,
  24. j = lower.summ$j,
  25. x = lower.summ$x,
  26. dims = dim(myMatrix))
  27. # 3 x 3 sparse Matrix of class "dgCMatrix"
  28. #
  29. # [1,] . . .
  30. # [2,] 1 . .
  31. # [3,] 2 . .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement