i have list of data frames want save independent .csv files.
currently have new line each data frame:
write.csv(lst$df1, "c:/users/.../df1") write.csv(lst$df2, "c:/users/.../df2") ad nauseam
obviously isn't ideal: change in names mean going through every case , updating it. considered using
lapply(lst, f(x) write.csv(x, "c:/users/.../x")
but won't work. how save each data frame in list separate .csv file?
you can this:
n <- names(lst) (i in seq_along(n)) write.csv(lst[[i]], file=paste0("c:/users/.../"), n[i], ".csv")
following comment of heroka shorter version:
for (df in names(lst)) write.csv(lst[[df]], file=paste0("c:/users/.../"), df, ".csv")
or
lapply(names(lst), function(df) write.csv(lst[[df]], file=paste0("c:/users/.../"), df, ".csv") )
Comments
Post a Comment