View source: R/cast_dim2flat.R
| cast_dim2flat | R Documentation |
cast_dim2flat() casts a dimensional list
(i.e. recursive array)
into a flat list
(i.e. recursive vector),
but with names that indicate the original dimensional positions of the elements.
Primary purpose for this function
is to facilitate printing or summarizing dimensional lists.
cast_dim2flat(x, ...)
## Default S3 method:
cast_dim2flat(x, ...)
x |
a list |
... |
further arguments passed to or from methods. |
A flattened list,
with names that indicate the original dimensional positions of the elements.
broadcast_casting
x <- array(
sample(list(letters, month.name, 1:10 ~ "foo"), prod(4:2), TRUE),
dim = 4:2,
dimnames = list(NULL, LETTERS[1:3], c("x", "y"))
)
# summarizing ====
summary(x) # dimensional information is lost
# In the following instances, dimensional position info is retained:
cast_dim2flat(x) |> summary()
cast_dim2flat(x[1:3, 1:2, 2, drop = FALSE]) |> summary()
cast_dim2flat(x[1:3, 1:2, 2, drop = TRUE]) |> summary()
# printing ====
print(x) # too compact
cast_dim2flat(x) |> print() # much less compact
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.