| reorient_vector | R Documentation |
The lhs %orientbc<-% rhs operator
takes an oriented vector (lhs),
and changes its orientation.
It also makes lhs a broadcaster if it wasn't already.
The modification is done directly on lhs itself,
using R's native semantics.
lhs %orientbc<-% rhs
lhs |
an atomic or recursive oriented vector. |
rhs |
an integer vector. |
In the context of broadcasting,
an oriented vector x is a vector or array that satisfies the following conditions:
It has length > 1 and <= (2^31 - 1);
It has no dimensions,
or one dimension is length(x) and all other dimensions are 1.
The orientation of an oriented vector is the index of the dimension with size > 1.
For example, if array lhs has dimensions c(1, 10, 1),
its orientation is 2L,
since the second dimension has size > 1.
A vector with no dimensions has orientation 1L.
In the context of broadcasted operations,
oriented vectors can be used to modify an array along a dimension.
The examples section gives several examples of this.
Nothing, but changes lhs directly.
broadcast_casting
# basic usage ====
x <- setNames(1:10, letters[1:10])
print(x)
x %orientbc<-% 2L
print(x)
x %orientbc<-% 3L
print(x)
x %orientbc<-% 1:2
print(x)
x %orientbc<-% c(1, 3)
print(x)
# modify an array along one specific dimension ====
x <- array(sample(0:9), c(3,3,3))
print(x)
# add 10 to second column, and 100 to third column:
v <- vector2array(c(0, 10, 100), 2, 2, TRUE)
x + v
# add 10 to second row, and 100 to third row:
v %orientbc<-% 1L
x + v
# add 10 to second layer, and 100 to third layer:
v %orientbc<-% 3L
x + v
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.