Transform a data.frame into a hierarchically organized array using dplyr in r

38 Views Asked by At

I have a data.frame with thousands of rows and 6 columns, I would like to make an array hierarchically organized according to 5 columns.

Here's the a sample of my data:

YEAR<-rep(c(2016,2017), 10)
BIOME<-c(rep("AM",8),rep("AF",8), rep("AF",4))
PROJECT<- c(rep("Gurupi",4), rep("Juruena",4),rep("Veracel",4),rep("Ipanema",4),rep("Caima",4))
PLACE<-c(rep("Gu.1",2),rep("Gu.2",2),rep("Ju.1",2),rep("Ju.2",2),rep("Ve.1",2),rep("Ve.2",2),rep("Ip.1",2),rep("Ip.2",2),rep("Ca.1",2),rep("Ca.2",2))
SP<-rep(c("sp.1", "sp.2"), 10)
AB<-rep(3:2,10)
DATA<-as.data.frame(cbind(BIOME, PROJECT, YEAR, PLACE, SP, AB))

I´d like to create an array of 5 dimensions, with the first two dimensions being the PLACE (rows) and SP (columns) and AB being the SP values (abundance), a third dimension being the YEAR, a fourth dimension being the PROJECT and the fifth dimension being the BIOME.

An object that would look something like this

ARRAY[PLACE,SP,YEAR,PROJECT,BIOME]

Where the data.frames are organized by PLACES (rows) sampling the AB of several SP (columns) for each YEAR, hierarchically organized within the same PROJECT and within the same BIOME.

I'm paralyzed by this and any help will be very welcome.

best wishes

I tried to split data and after transform each list object in arrays, but I couldn´t provide de hierarchy order on it.

0

There are 0 best solutions below