I am looking for a more universal way to get a multidimensional array from data.frame.
I would like to be able to create as many dimensions as needed from the number of variables in the data frame as I wish.
Currently, the method must be adapted to each data.frame file; it requires subclasses to form a vector.
I would like something using the melt / cast method in plyr.
data<-data.frame(coord.name=rep(1:10, 2), x=rnorm(20), y=rnorm(20), ID=rep(c("A","B"), each=10)) data.array<-array(dim=c(10, 2, length(unique(data$ID)))) for(i in 1:length(unique(data$ID))){ data.array[,1,i]<-data[data$ID==unique(data$ID)[i],"x"] data.array[,2,i]<-data[data$ID==unique(data$ID)[i],"y"] } data.array , , 1 [,1] [,2] [1,] 1 1 [2,] 3 3 [3,] 5 5 [4,] 7 7 [5,] 9 9 [6,] 1 1 [7,] 3 3 [8,] 5 5 [9,] 7 7 [10,] 9 9 , , 2 [,1] [,2] [1,] 2 2 [2,] 4 4 [3,] 6 6 [4,] 8 8 [5,] 10 10 [6,] 2 2 [7,] 4 4 [8,] 6 6 [9,] 8 8 [10,] 10 10