I am reading in multiple csv files (~50) from a folder and combining them into a single dataframe. I want to keep their original file names attached to their data and add it as its own column.
I have run this code:
all_paths <-
list.files(path = "C:/Users/pwern/Documents/Maui Tiger Shark Acoustic Monitoring/Maui Tiger Shark Acoustic Monitoring/data inputs/Vemco Receiver Files/relevant maui detection files",
pattern = "*.csv",
full.names = TRUE)
all_content <-
all_paths %>%
lapply(read.table,
header = TRUE,
sep = "|",
encoding = "UTF-8")
all_filenames <- all_paths %>%
basename() %>%
as.list()
all_lists <- mapply(c, all_content, all_filenames, SIMPLIFY = FALSE)
all_result <- rbindlist(all_lists, fill = T)
but my all_result df ends up with only two columns, the first of which is all my data combined into one column and the second is the file names. I can't figure out where I am going wrong with the separation? Thank you in advance for your help