I have over 100 CSV files with each containing information only within the first 2-rows (i.e. row-1 and row-2). Row-1 contains the column headings and Row-2 contains the data. The column headings are the same for all the CSV files but only the data (in row-2) varies. I will like to have all the data captured in one CSV file under the same column headings. This could be achieved using Copy or Cut and Paste option in EXCEL but considering the large number of files I am working with, it will be prudent to instead have a code to simplify this task. I will appreciate it greatly if anyone could share with me a code for achieving this objective. Thank you in advance for your consideration.
Have a look at this link. It should help
This is a pre-processing task better performed outside
R. From the terminal directory containing the csv files (and only those files) to be processed.
$ head 1 * > collect $ head 2 * | tail -1 >> collect $ mv collect collect.csv
readr::read_csv("collect.csv") -> dat
files <- list.files(path = ".", pattern = ".csv", full.names = TRUE) # adapt to capture all desired files df <- purrr::map_dfr(files, readr::read_csv, n_max = 1)
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.