# NOT RUN {
x <- rray(c(20:11, 1:10), dim = c(5, 2, 2))
# Flatten, sort, then reconstruct the shape
rray_sort(x)
# Sort, looking along the rows
rray_sort(x, 1)
# Sort, looking along the columns
rray_sort(x, 2)
# Sort, looking along the third dimension
# This switches the 20 with the 1, the
# 19 with the 2, and so on
rray_sort(x, 3)
# ---------------------------------------------------------------------------
# Dimension names
y <- rray(
c(2, 1, 1, 2),
dim = c(2, 2),
dim_names = list(
r = c("r1", "r2"),
c = c("c1", "c2")
)
)
# Dimension names are dropped along the axis you sort along
rray_sort(y, 1)
rray_sort(y, 2)
# All dimension names are dropped if `axis = NULL`
rray_sort(y)
# }
Run the code above in your browser using DataLab