I'm trying to apply the code here which uses ldply to combine multiple csv files into one dataframe
I'm trying to figure out what the appropriate tidyverse
syntax is to add a column that lists the name of the file from which the data comes from.
Here's what I have
test <- ldply( .data = list.files(pattern="*.csv"),
.fun = read.csv,
header = TRUE) %>%
mutate(filename=gsub(".csv","",basename(x)))
I get
"Error in basename(x) : object 'x' not found message".
My understanding is that basename(path), but when I set the path as the folder which contains the file, the filename column that ends up getting added just has the folder name.
Any help is much appreciated!