I have a data frame that I want to convert to a three-dimensional array. One of the columns in the data frame should serve as the grouping variable for splitting the frame i
Here is what I'd probably do:
library(abind) abind(split(df, df$i), along=3) # , , 1 # # i x y l # 5 1 0 0 -0.56047565 # 6 1 0 1 -0.23017749 # 7 1 1 0 1.55870831 # 8 1 1 1 0.07050839 # # , , 2 # # i x y l # 5 2 0 0 0.1292877 # 6 2 0 1 1.7150650 # 7 2 1 0 0.4609162 # 8 2 1 1 -1.2650612