Reputation: 95
Considering there are several files with different number of rows like the following:
Using R, I need to add them in one csv file at the end of each other with an extra column of the type of people (old, young , ...) like:
Cab you help me know which commands I should use for that.
Upvotes: 1
Views: 110
Reputation: 887251
We can get load the '.csv' files in a list
, read them with read_csv
(from readr
) by loopiing over the files with imap
library(purrr)
library(readr)
files <- list.files(pattern = '\\.csv', full.names = TRUE)
names(files) <- tools::file_path_sans_ext(basename(files))
out <- imap_dfr(files, read_csv, .id = 'age')
Upvotes: 1