| rray-rep | R Documentation |
rray_rep() repeats whole axes of x in bulk, i.e. repeat all of the
columns 5 times. It can repeat several axes at once, with one times
per axis.
rray_rep_each() repeats each individual element of the axis of x
separately, i.e. repeat the first column 2 times, the second column 3
times, and so on. For convenience, you can also provide a single number
to repeat each element along the axis the same number of times.
These are the array versions of vctrs::vec_rep() and
vctrs::vec_rep_each(), which repeat along the size of a vector rather than
along an axis.
rray_rep(x, ..., times, axes)
rray_rep_each(x, ..., times, axis)
x |
An array. |
... |
These dots are for future extensions and must be empty. |
times |
For For |
axes |
The axes to repeat along, given by position or by title. |
axis |
The axis to repeat along, given by position or by title. |
Names repeat alongside the data, so a repeated axis can come back with
duplicate names. Every other axis keeps its names untouched. The titles of
x are kept.
An array with the same dimensions as x, except along the repeated axes.
x <- array(1:6, c(3, 2))
# All rows in bulk, twice
rray_rep(x, times = 2, axes = 1)
# Each row individually, twice
rray_rep_each(x, times = 2, axis = 1)
# Columns rather than rows
rray_rep(x, times = 2, axes = 2)
# Rows and columns, twice each
rray_rep(x, times = 2, axes = c(1, 2))
# Rows twice and columns three times
rray_rep(x, times = c(2, 3), axes = c(1, 2))
# A different number of repeats per row
rray_rep_each(x, times = c(1, 2, 3), axis = 1)
# A different number of repeats per row, by title
z <- rray_set_titles(x, c("row", "col"))
rray_rep_each(z, times = c(1, 2, 3), axis = "row")
# Zeroes drop slices entirely
rray_rep_each(x, times = c(1, 0, 2), axis = 1)
# Names repeat with the data, duplicates and all
y <- array(1:6, c(3, 2), dimnames = list(c("a", "b", "c"), c("x", "y")))
rray_names(rray_rep(y, times = 2, axes = 1))
rray_names(rray_rep_each(y, times = 2, axis = 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.