Is it possible to save documents within a for-loop such that the i’th run will save a document called i.txt? I tried the obvious:
for (i in 1:10) {
...
write.table(temp,file="i.txt",sep="\t", col.names=NA)
}
but this just saves one file called i.txt. Any way to do this easily? Thanks.
When you write
file="i.txt"you are creating a fixed character string, i.e."i.txt".You need to add some code that takes the current value of
iand uses it in the string. One option is to usepaste:Or use the new (in R 2.15.0) shortcut function
paste0which usessep=""by defaultTherefore, try: