I have imported a *.mat data set of ECG data and it turns out to be an array nested in a list with (1:19, 1:2000, 1:45) dimensions.
I'd like to convert this array into a data.table in long format where each of the 1:45 are 'ids'. I like the look of reshape2 and tidyr but I don't see an easy way of doing it when a 'list' is involved. Any thoughts?
ADDED: E.g. as the following picture:
EDIT: Added dput from ECGa
dput(ECGa[1:4,1:4,1:4])
structure(c(0.266687798848186, 0.243782451327742, 0.256932437720159,
0.298861598151174, 0.198233672667731, 0.0917952258522064, 0.0911852809187542,
0.0896079263551856, 0.236398290801764, 0.0864552727199747, 0.0745517747485495,
0.141094205953345, 0.134887167694073, 0.0747942533151883, 0.0955856952160322,
0.0351423350784724, 0.0280172116375036, 0.0137183766752048, 0.00632054977574689,
0.0140727955279187, 0.0690137281047283, 0.078048395374513, 0.103558903741209,
0.0440585188615387, 0.156352265056089, 0.112594108595364, 0.162727838219577,
0.171253189308951, 0.10110879614821, 0.0815894300030362, 0.11782535820017,
0.0422632188213653, 0.0555849641766514, 0.0677027788598739, 0.0459698146330784,
0.0388415858274208, 0.0843241755529416, 0.0607574029475139, 0.0572549162201976,
0.0507991887467287, 0.0505785290171543, 0.064132492222132, 0.0527843866043094,
0.0354988312446934, 0.104654374350645, 0.0881949907935882, 0.0429712078085868,
0.0576943626267035, 0.0382280461459995, 0.124883693856915, 0.0481763535955804,
0.0397818749456581, 0.0782161984603273, 0.155594086108477, 0.121039425233015,
0.0563997196467123, 0.0513952066155024, 0.209997229543773, 0.0745673273804948,
0.0647872565452434, 0.0801540099609934, 0.147046389860838, 0.162708859129276,
0.0766361733056703), .Dim = c(4L, 4L, 4L), .Dimnames = list(NULL,
c("P7", "P4", "Cz", "Pz"), NULL))
I've tried doing: ECGa<-as.data.frame(ECGa) gives the right dimensions but it renames all the columns (e.g. the first becomes P7.1, P7.2 ... P7.45) I want to make a new column called ID that gives a value of 1 for the first patient and 2 for the second, up to 45 for the forty fifth.
NEW ADDITION:
I've found that using abind
does part of the job I want. But imagine I had a 1000 arrays, can I automate it?
e.g.
abind(ECGa[,,1],ECGa[,,2],ECGa[,,3],ECGa[,,4],ECGa[,,5],along=1)
> dim(abind(ECGa[,,1],ECGa[,,2],ECGa[,,3],ECGa[,,4],ECGa[,,5],along=1))
[1] 10000 19