Amin
Amin

Reputation: 368

Creating data structure containing factors and matrices

I have 6 matrices of size 100*50 (e.g. m1-m6) and 6 matrices of size 100*100 (m7-m12). these matrices are nested withing two factors as F and G. I want to create a data structure that reflects this design:

F1  G1  m1
F1  G2  m2
F1  G3  m3
F1  G1  m4
F1  G2  m5
F1  G3  m6
F2  G1  m7
F2  G2  m8
F2  G3  m9
F2  G1  m10
F2  G2  m11
F2  G3  m12

I want to use these structure for ANOVA and plotting the results. Each matrix consists of values over 100 replications. The m1-m12 matrices are stored in csv files.So, I need to import the matrices and create the data structure.I tried array or list but I couldn't find an efficient and correct way for doing that.

Any idea?

Upvotes: 0

Views: 88

Answers (1)

agstudy
agstudy

Reputation: 121568

You can use array, First I create data structure:

A1 = array(0,dim=c(100,50,6))
A2 = array(0,dim=c(100,100,6))

I assume you have 2 list of file names , list_files1 and list_files2:

lapply(seq_along(list_files1),function(x){
  A1[,,x] <- read.csv(list_files1[[x]])
})
lapply(seq_along(list_files2),function(x){
  A2[,,x] <- read.csv(list_files2[[x]])
})

Upvotes: 1

Related Questions