Array
  • store data in more than two dimensions
  • Create Array
    # create a 3d array
    A = array(1:12, dim = c(2, 3, 2))
    print(A)
    
    # create a 3d empty array
    B = array(0, dim = c(2, 3, 2))
    print(B)
    		
    Accesing
    # create a 3d array
    A = array(1:12, dim = c(2, 3, 2))
    
    print(A[, , 2]) # second matrix
    print(A[1, , 1]) # first row of the first matrix
    		
    Operations
    # create a 3d array
    A = array(1:12, dim = c(2, 3, 2))
    print(A)
    
    B = apply(A, c(1), sum) # all rows
    B = apply(A, c(2), sum) # all column
    B = apply(A, c(3), sum) # all matrices
    B = apply(A, c(1, 2), sum) # sum of element along all matrices direction
    print(B)