'Extracting column name from CSV filename during import

I have 24 CSV files to import, each with three columns of data: type (CHR), buffer (INT), mean (NUM). I import these using:

data <- list.files(path = "...", pattern = "*.csv", full.names = TRUE) %>% 
lapply(read_csv) %>%                                            
bind_rows

This creates a 'long' data table containing three columns of data.

To enable monthly analysis I need to extract a date from the filename of each imported CSV to create a 'wide' table (with a column for each date), or a 'long' table with date as another column).

Although I've found quite a few suggested ways of doing this I can't get anything to work (I'm relatively new to R) and have become a b it confused by unfamiliar syntax.

The CSV filename is in the format ABC_YYYY-MM-DD.CSV

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source