I have 6-10 data frame objects I'd like to write out. Right now I have to manually write each one out with write.table
. I'd like to simplify my code and loop through the objects and write them all out.
I've tried the suggestions here:
Write to files in R using a loop
writing many files in a for loop using R
However, I keep getting files that are correctly named but look like this:
> "x"
"1" "listdata_cent"
Here is an example of my code:
names(lst) <- (ls(pattern = "^listdata"))
lst <- as.list((ls(pattern = "^listdata")))
for (i in nam) {
write.table(i, file = paste(i, ".txt", sep = ""), col.names= TRUE, sep = "\t")
}
Any help you can give would be greatly appreciated. I'm sure I'm missing something simple.