0

I have multiple csv files in a directory. How can I create a 3D array while reading them in R?

Here is what I tried:

temp <- list.files(pattern="*.csv")
myfiles <- lapply(temp, read.delim)

This creates a list but I am not sure how to create 3D array from here. Any thoughts?

  • 1
    If your data is properly set up, you could do `array(unlist(myfiles), dim=c(dim(myfiles[[1]], length(myfiles))`. – lmo Nov 13 '17 at 17:09
  • Thanks, I tried your suggestion but it seems to be incomplete – Maxiths Nov 13 '17 at 17:15
  • Without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), that's about the best I can do. – lmo Nov 13 '17 at 17:26
  • Thanks, it works – Maxiths Nov 13 '17 at 23:26
  • For those of you, who will come here and fail at running the command above. Here is the working version ( a few closing brackets are missing): `array(unlist(myfiles), dim=c(dim(myfiles[[1]]), length(myfiles)))` – Urvah Shabbir Aug 11 '18 at 21:02

0 Answers0