Last active
August 15, 2017 14:16
-
-
Save arcaravaggi/eb7c1ab87a2dfd75aebfdf19757aeb63 to your computer and use it in GitHub Desktop.
Export all active dataframes to named csv files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create labelled list of all active dataframes | |
my.list <- mget(ls(pattern="*_UMAC")) | |
# Use write.csv in a for loop, creating files for each and naming | |
# according to label (i.e. df name) | |
for (i in seq_along(my.list)){ | |
write.csv(my.list[i], paste(names(my.list)[i], ".csv"), col.names = TRUE) | |
} | |
# Or this, which retains column names HT @RallidaeRule | |
for(i in 1:length(my.list)){ | |
name <- names(my.list)[i] | |
write.csv(my.list[[i]], file=paste0(name,".csv")) | |
} | |
# Or, using mapply HT @thosjleeper | |
mapply(write.csv, my.list, paste0(names(my.list), ".csv")) | |
# If you want a character string of all active dataframes, for whatever reason, consider | |
list <- names(which(unlist(eapply(.GlobalEnv,is.data.frame)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment