DJ-AFC DJ-AFC - 1 year ago 70
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")

Any simple solution here?

Answer Source

Use the command get()

for (i in 1:10) {
  write.table(get(paste0("file", i)), file=paste0("C:/.../file",i,".txt"), sep="\t")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download