I was wondering how I can handle 2500 .csv files with the same number of columns (i.e., 4 columns)? I want to import these files, remove the first and second columns, change the title of the remaining columns to x and y, remove duplicates in each data frame, and finally save these data frames as separate .csv files (2500 files). I have used the following script:
library(dplyr)
# Get all filenames
list.files(path = "D:/R_project", full.names = `TRUE) %>%`
# Import all files
purrr::map(readr::read_csv) %>%
purrr::map(
~ .x %>%
# Select columns and rename
select(
x = Col3,
y = Col4
) %>%
# Remove duplicates
distinct()
) %>%
# Save all files (same filename, but in a different folder)
purrr::walk2(
list.files("D:/R_project/Treated"),
~ readr::write_csv(x = .x, file = paste0("output/folder/", .y))
)
However, I received this error for all of the data frames in the end (below is an example for one of the data frames):
Rows: 1579 Columns: 4
Column specification ---------------------------------------
Delimiter: ","
i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
New names:
* `` -> ...1
How can I rectify the problem? any helps?