rray_bind: Combine many arrays together into one array

Description Usage Arguments Details Value Examples

View source: R/bind.R

Description

These functions bind multiple vectors, matrices, arrays, or rrays together into one, combining along the .axis.

Usage

1
2
3
4
5

Arguments

...

Vectors, matrices, arrays, or rrays.

.axis

A single integer. The axis to bind along.

Details

rray_bind() is extremely flexible. It uses broadcasting to combine arrays together in a way that the native functions of cbind() and rbind() cannot. See the examples section for more explanation!

Value

An array, or rray, depending on the input.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# ---------------------------------------------------------------------------
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)

DavisVaughan/rray documentation built on Feb. 5, 2020, 10:06 p.m.