F. De Leo F. De Leo - 1 year ago 77
R Question

Naming output files in R

I'm working in

and I would like to export a txt file putting in its name the value of a particular variable; I read about the command
and it works perfectly here:


is the value to put at the beginning of the file
. I would like to automatically put this file in an output folder where I keep all the other results. I try to do something like this:


But it doesn't work. Any suggestion?

Answer Source

paste() just creates a string by concatenating the individual values and uses a space as default separator:

write.table(mydata, file = paste("./output/", cn ,"data.txt", sep = ""))

or with paste0(...), which is equivalent to paste(..., sep = ""):

write.table(mydata, file = paste0("./output/", cn ,"data.txt"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download