Guest User

Untitled

a guest
Dec 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. myObject[,,1] # returns a square matrix
  2. myObject[,,2] # returns a square matrix of the same size
  3. ...
  4.  
  5. matrixSum <- myObject[,,1] + myObject[,,2] + myObject[,,3]
  6.  
  7. matrixSum <- apply(myObject, c(1,2), sum)
  8.  
  9. myObject <- array(c(1,2,3),dim = c(3,4,3))
  10. myObject
  11. , , 1
  12.  
  13. [,1] [,2] [,3] [,4]
  14. [1,] 1 1 1 1
  15. [2,] 2 2 2 2
  16. [3,] 3 3 3 3
  17.  
  18. , , 2
  19.  
  20. [,1] [,2] [,3] [,4]
  21. [1,] 1 1 1 1
  22. [2,] 2 2 2 2
  23. [3,] 3 3 3 3
  24.  
  25. , , 3
  26.  
  27. [,1] [,2] [,3] [,4]
  28. [1,] 1 1 1 1
  29. [2,] 2 2 2 2
  30. [3,] 3 3 3 3
  31.  
  32. apply(myObject, c(1,2), sum)
  33. [,1] [,2] [,3] [,4]
  34. [1,] 3 3 3 3
  35. [2,] 6 6 6 6
  36. [3,] 9 9 9 9
  37.  
  38. rowSums(myObject, dims = 2)
  39. [,1] [,2] [,3] [,4]
  40. [1,] 3 3 3 3
  41. [2,] 6 6 6 6
  42. [3,] 9 9 9 9
Add Comment
Please, Sign In to add comment