rray_expand() inserts a new dimension at the axis dimension. This expands the number of dimensions of x by 1.

rray_expand(x, axis)

Arguments

x

An rray.

axis

An integer of size 1 specifying the location of the new dimension.

Value

x with a new dimension inserted at the axis.

Details

Dimension names are kept through the insertion of the new dimension.

Examples

x <- rray(1:10, c(5, 2)) x <- rray_set_row_names(x, letters[1:5]) x <- rray_set_col_names(x, c("c1", "c2")) # (5, 2) # Add dimension to the front # (1, 5, 2) = 1 row, 5 cols, 2 deep rray_expand(x, 1)
#> <rray<int>[,5,2][1]> #> , , c1 #> #> a b c d e #> [1,] 1 2 3 4 5 #> #> , , c2 #> #> a b c d e #> [1,] 6 7 8 9 10 #>
# (5, 2) # Add dimension to the middle # (5, 1, 2) = 5 rows, 1 col, 2 deep rray_expand(x, 2)
#> <rray<int>[,1,2][5]> #> , , c1 #> #> [,1] #> a 1 #> b 2 #> c 3 #> d 4 #> e 5 #> #> , , c2 #> #> [,1] #> a 6 #> b 7 #> c 8 #> d 9 #> e 10 #>
# (5, 2) # Add dimension to the end # (5, 2, 1) = 5 rows, 2 cols, 1 deep rray_expand(x, 3)
#> <rray<int>[,2,1][5]> #> , , 1 #> #> c1 c2 #> a 1 6 #> b 2 7 #> c 3 8 #> d 4 9 #> e 5 10 #>
# In some cases this is different than a simple # rray_reshape() because the dimension names # follow the original dimension position # - 5 row names follow to the new 5 column position # - 2 col names follow to the new 2 deep position # - result has no row names because that is the new axis rray_expand(x, 1)
#> <rray<int>[,5,2][1]> #> , , c1 #> #> a b c d e #> [1,] 1 2 3 4 5 #> #> , , c2 #> #> a b c d e #> [1,] 6 7 8 9 10 #>
# A reshape, on the other hand, # drops all dimension names rray_reshape(x, c(1, 5, 2))
#> <rray<int>[,5,2][1]> #> , , 1 #> #> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 2 3 4 5 #> #> , , 2 #> #> [,1] [,2] [,3] [,4] [,5] #> [1,] 6 7 8 9 10 #>