rray_transpose: Transpose an array

Description Usage Arguments Details Value Examples

View source: R/transpose.R

Description

rray_transpose() transposes x along axes defined by permutation. By default, a standard transpose is performed, which is equivalent to permuting along the reversed dimensions of x.

Usage

1
2
3
4
rray_transpose(x, permutation = NULL)

## S3 method for class 'vctrs_rray'
t(x)

Arguments

x

A vector, matrix, array, or rray.

permutation

This should be some permutation of 1:n with n being the number of dimensions of x. If NULL, the reverse of 1:n is used, which is the normal transpose.

Details

Unlike t(), using rray_transpose() on a vector does not transpose it, as it is a 1D object, and the consistent result of transposing a 1D object is itself.

t.vctrs_rray() uses the base R's t() behavior to be consistent with user expectations about transposing 1D objects.

There is an aperm() method for rray objects as well. Unlike base R, it currently does not accept character strings for perm.

Value

x transposed along the axes defined by the permutation.

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
x <- rray(
 1:6,
 c(3, 2),
 dim_names = list(rows = c("r1", "r2", "r3"), cols = c("c1", "c2"))
)

# A standard transpose
rray_transpose(x)

# Identical to
rray_transpose(x, rev(1:2))

x_3d <- rray_broadcast(x, c(3, 2, 2))

# transpose here is like setting
# `permutation = c(3, 2, 1)`
# so the result should change _shape_ like:
# (3, 2, 2) -> (2, 2, 3)
rray_transpose(x_3d)

# This transposes the "inner" matrices
# (flips the first and second dimension)
# and leaves the 3rd dimension alone
rray_transpose(x_3d, c(2, 1, 3))

# ---------------------------------------------------------------------------
# Difference from base R

# Coerces 1:5 into a 2D matrix, then transposes
t(1:5)

# Leaves it as a 1D array and does nothing
rray_transpose(1:5)

# t.vctrs_rray() has the same behavior
# as base R
t(rray(1:5))

rray documentation built on July 23, 2019, 5:04 p.m.