Q:

2D matrix into 3D array as go thru for loop without abind

So I have 24 files and each file has 2D matrix like this:
               V1        V2        V3        V4        V5        V6         V7     
1   0.9750000 0.9750000 0.9750000 1.1577778 1.1577778 1.1577778 1.32777778 1.32777778
2   0.6875000 0.6875000 0.6875000 0.7758333 0.7758333 0.7758333 1.19666667 1.19666667
3   0.6875000 0.6875000 0.6875000 0.7758333 0.7758333 0.7758333 1.19666667 1.19666667
4   0.6875000 0.6875000 0.6875000 0.7758333 0.7758333 0.7758333 1.19666667 1.19666667
5   0.9866667 0.9866667 0.9866667 1.2088889 1.2088889 1.2088889 1.43000000 1.43000000
6   0.9866667 0.9866667 0.9866667 1.2088889 1.2088889 1.2088889 1.43000000 1.43000000
7   0.9866667 0.9866667 0.9866667 1.2088889 1.2088889 1.2088889 1.43000000 1.43000000
8   0.9475000 0.9475000 0.9475000 1.1008333 1.1008333 1.1008333 1.36833333 1.36833333
9   0.9475000 0.9475000 0.9475000 1.1008333 1.1008333 1.1008333 1.36833333 1.36833333
10  0.9475000 0.9475000 0.9475000 1.1008333 1.1008333 1.1008333 1.36833333 1.36833333
11  1.0475000 1.0475000 1.0475000 1.0362500 1.0362500 1.0362500 1.20833333 1.20833333
12  1.0475000 1.0475000 1.0475000 1.0362500 1.0362500 1.0362500 1.20833333 1.20833333
13  1.0475000 1.0475000 1.0475000 1.0362500 1.0362500 1.0362500 1.20833333 1.20833333
14  0.6133333 0.6133333 0.6133333 0.5950000 0.5950000 0.5950000 0.63222222 0.63222222
15  0.6133333 0.6133333 0.6133333 0.5950000 0.5950000 0.5950000 0.63222222 0.63222222
16  0.6175000 0.6175000 0.6175000 0.5950000 0.5950000 0.5950000 0.60000000 0.60000000
17  0.6175000 0.6175000 0.6175000 0.5950000 0.5950000 0.5950000 0.60000000 0.60000000
18  0.6175000 0.6175000 0.6175000 0.5950000 0.5950000 0.5950000 0.60000000 0.60000000
19  0.5366667 0.5366667 0.5366667 0.5150000 0.5150000 0.5150000 0.49000000 0.49000000

And I want to put data in 3D matrix. So I read one file, put in 3D array, and read next file, then put the new data over the first one, but not rewrite.
I got reading data part, and I set my 3D array like this:
k<-24
data<-array(0,dim=c(200,200,length(k))

200,200,24 is basically describes number of data elements in each file (40000 elements) and 24 files.
Then I do this:
for (i in 1: length(k) {
    listing <- read.csv(datafiles[i])

data dimension is 200 201 somewhat so do next step to make it 200 by 200
data2<- listing[,-1]

now it is 2D matrix, so I want to put them in 3D array I made earlier.
I coded like this:
data3[,,i]<-matrix(data2, ncol=200,nrow=200)
}

So after I finish reading and reshaping data frame, I should get 24 data (200 by 200) files as one big pile of matrices. Like box of data......But I get this error with this code:
Error in data3[, , i] <- matrix(data2, ncol =200, nrow = 200) : 
  incorrect number of subscripts

Does anyone have advice on this coding without abind?
Thank you

A:

I assume your files in the same directory, I proceed like this
temp = list.files(pattern="*.csv")
named.list <- lapply(temp, read.csv)

To get 200 x 200 x 24 array continue with this:
require(abind)
arr <- abind(named.list,along=3)

A:

A clumsy way without abind that nevertheless leads to the desired result is:
First, read in your data not as as a data.frame but as a vector
dat1 <- as.vector( unlist( read.csv( "dat1.csv" ) ) )   
dat2 <- as.vector( unlist( read.csv( "dat2.csv" ) ) ) 
# and so on, or whatever for loop you are using

Then, concatenate them to one vector of 960000 elements with
x <- c( dat1, dat2, ... )   # or whatever your names are

Finally, transform that vector into the desired array with
x <- array( x, dim = c( 200, 200, 24 ) )

