dfToArray: Convert a data frame to an array.

Description Usage Arguments Value References Examples

View source: R/utils.R

Description

Convert a data frame to an array.

Usage

1
dfToArray(df, dimOrders = NULL)

Arguments

df

data.frame. dim = c(nr, nc). The first (nc - 1) columns represent dimensions. The last column gives values in the array.

dimOrders

list of vector. Ordering (i.e., factor levels) of each dimension in the array. Must be a fully named list (arbitrary length) or fully unnamed list (length = nc). If a column ordering is given for a column, any values present in that column but not in the ordering assumes a value of NA. Any columns for which an ordering is not given is sorted lexicographically. The class of each vector should match the class of the corresponding column.

Value

array. mode = mode(df[[length(df)]]). Mode of array is the same as the mode of the values column (i.e., last column) in the data frame.

References

https://stackoverflow.com/a/9617424, https://stackoverflow.com/a/46129338.

Examples

1
dfToArray(CO2) # CO2 data frame exported from datasets package

bentyeh/r_bentyeh documentation built on Jan. 1, 2021, 4:59 p.m.