I have a named list of data frames and want to write each data frame out to a CSV, using the data frame name as the filename. How can I modify my function to do that? The function below gives me the entire data frame in the file name instead of the name of the data frame.
a <- data.frame('col1' = c(1,2,3))
b <- data.frame('col1' = c(3,4,5))
mylist <- list(a,b)
names(mylist) <- c('a', 'b')
lapply(mylist, function(x) write.csv(x, file = paste0(x, '.csv')))