0

I have a list of 42 csv files with each with 2 columns. Timestamp in first column and some values in the other column. Timestamp column is same for each files. I added all the files into a list as follows-

files = list.files(pattern = "*.csv") %>% 
lapply(read_csv) %>%
lapply(na.omit) # just to omit the blank entry from each files which located as the last entry of each files.

Now I want to combine all these files into one df where the first column is the timestamp and the 42 columns representing the values for each files. But unfortunately I am not getting my way around of it. Can you please help? Thank you.

Rel_Ai
  • 581
  • 2
  • 11
  • Try `Reduce(function(...) merge(..., by = c("Timestamp")), files)` – akrun Aug 25 '19 at 20:06
  • The zoo package can do most of this in one line: `library(zoo); z <- read.csv.zoo(c("csv1.csv", "csv2.csv"))` Have illustrated with two input files but any number are allowed. You may need to specify `format=` if the dates are not in the standard format since it will attempt to convert them to `Date` class (or other class that you specify). After this you can just leave result as a zoo object `z` or convert it to a data frame using `fortify.zoo(z)`. You ma – G. Grothendieck Aug 25 '19 at 20:15

0 Answers0