df_to_array.Rd
Convert a data.frame to array format.
df_to_array(df, indexes)
df | A data.frame with the indexes columns and a value column. |
---|---|
indexes | A names list with the indexes for the array. |
An array with the indexes dimension.
library(emr) set1 <- c("A", "B") set2 <- c("C", "D") set3 <- c("imp", "exp") sets <- list( set1 = set1, set2 = set2, set3 = set3 ) x <- expand.grid( set1 = set1, set2 = set2, set3 = set3, stringsAsFactors = TRUE ) x$value <- 1:8 df_to_array(x, sets[(c('set1', 'set2', 'set3'))])#> , , set3 = imp #> #> set2 #> set1 C D #> A 1 3 #> B 2 4 #> #> , , set3 = exp #> #> set2 #> set1 C D #> A 5 7 #> B 6 8 #>