Description Usage Arguments Details Value Examples
rray_rotate()
rotates an array along the plane defined by c(from, to)
. It
can be thought of as sequentially rotating the array 90 degrees a set number
of times
.
1 | rray_rotate(x, from = 1, to = 2, times = 1)
|
x |
A matrix, array, or rray. |
from, to |
Single integer values. The direction of the rotation goes
from |
times |
A single integer. The number of times to perform the rotation.
One of: |
A rotation can be a hard thing to wrap your head around. I encourage looking at the examples and starting with 2D to try and understand what is happening before moving up to higher dimensions.
Note that a rotation is not the same thing as a transpose.
Generally, you can predict the output of rotating using from
and to
by switching the dimensions at the from
and to
axes position. This gives
you the shape of the output. So, a (5, 2, 4)
array rotated using from = 1
and to = 3
would have a resulting shape of (4, 2, 5)
. Note that using
from = 3
and to = 1
would give the same shape. The "direction"
of how these are rotated is controlled by the ordering of from
and to
.
x
rotated along the axis described by from
and to
.
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 | # ---------------------------------------------------------------------------
# 2D example
x <- rray(1:6, c(3, 2))
x <- rray_set_row_names(x, c("r1", "r2", "r3"))
x <- rray_set_col_names(x, c("c1", "c2"))
# "counter clockwise" rotation turning the
# rows into columns
rray_rotate(x)
# "clockwise" by reversing the direction
rray_rotate(x, from = 2, to = 1)
# Rotate twice (180 degrees)
# Direction doesn't matter here, the following
# give the same result
rray_rotate(x, times = 2)
rray_rotate(x, from = 2, to = 1, times = 2)
# ---------------------------------------------------------------------------
# 3D example
x_3d <- rray_expand(x, 3)
# - Rotations on the (1, 3) axis plane
# - Dimensions go from (3, 2, 1) -> (1, 2, 3) in both cases
# - And the direction of how that happens is controlled
# by `from` and `to`
rray_rotate(x_3d, from = 1, to = 3)
rray_rotate(x_3d, from = 3, to = 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.