DJ-AFC DJ-AFC - 18 days ago 5
R Question

Creating multiple consecutive output tables

I am attempting to write out hundreds of tables in R that follow a simple consecutive numerical sequence. I'm assuming this must be very simple but can't find a straightforward answer anywhere. My data takes the form:

write.table(file1, file="C:/.../file1.txt", sep="\t")
write.table(file2, file="C:/.../file2.txt", sep="\t")
write.table(file3, file="C:/.../file3.txt", sep="\t")
etc...


Any simple solution here?

Answer

Use the command get()

for (i in 1:10) {
  write.table(get(paste0("file", i)), file=paste0("C:/.../file",i,".txt"), sep="\t")
}
Comments