Mark
Mark

Reputation: 1769

Naming output file using more variables

I'm using a write.csv statement to direct output to a file. I have several variables in the program: 'n', 'k' and 'temp'. For example: n=100, k=0.1 and temp=2000.

I would like for the output csv files to be labeled 'file name t 2000 N 100 k 01.csv'. But with the following command:

    write.csv(res, file = paste0("file name t", temp,".csv"),row.names=FALSE)

I can write only 'file name t 2000.csv'. How could I write the correct label? Thanks!

Upvotes: 0

Views: 45

Answers (2)

Hack-R
Hack-R

Reputation: 23214

#'file name t 2000 N 100 k 01.csv'. 

a <- "file name t "
b <- 2000
c <- " N 100"
d <- " k 01"

write.csv(res, file = paste0(a, b, c, d, ".csv"),row.names=FALSE)

Upvotes: 1

Brian Stamper
Brian Stamper

Reputation: 2263

You can string together as many things as you want in paste0:

paste0("file name t", temp, "N", n, "k", k, ".csv")

Though you may need to adjust the spacing to your liking.

Upvotes: 1

Related Questions