# NOT RUN {
# ---------------------------------------------------------------------------
a <- matrix(1:4, ncol = 2)
b <- matrix(5:6, ncol = 1)
# Bind along columns
rray_bind(a, b, .axis = 2)
# Bind along rows
# Broadcasting is done automatically
rray_bind(a, b, .axis = 1)
# Notice that this is not possible with rbind()!
try(rbind(a, b))
# You can bind "up" to a new dimension
# to stack matrices into an array
rray_bind(a, b, .axis = 3)
# ---------------------------------------------------------------------------
# Dimension name example
x <- matrix(
1:6,
ncol = 3,
dimnames = list(c("a_r1", "a_r2"), c("a_c1", "a_c2", "a_c3"))
)
y <- matrix(
7:8,
ncol = 1,
dimnames = list(NULL, c("b_c1"))
)
# Dimension names come along for the ride
# following rray name handling
rray_bind(x, y, .axis = 2)
# If some inputs are named, and others
# are not, the non-named inputs get `""`
# as names
rray_bind(x, y, .axis = 1)
# You can add "outer" names to the
# axis you are binding along.
# They are added to existing names with `..`
rray_bind(outer = x, y, .axis = 2)
# Outer names can be used to give unnamed
# inputs default names
rray_bind(outer = x, outer_y = y, .axis = 1)
# }
Run the code above in your browser using DataLab