sacvf
sacvf

Reputation: 2533

How to put input of a function in the name of text file?

 myf<- function(col,row){
 x=5*col+row
 write.table(x,"res_row_col.txt")}
 myf(5,6)

I expected the file to be:

         res_5_6.txt

But the file was written as:

      res_row_col.txt

Upvotes: 0

Views: 53

Answers (2)

Quinn Weber
Quinn Weber

Reputation: 927

Use the paste0 function:

myf<- function(col,row){
x=5*col+row
write.table(x,paste0("res_", row, "_", col, ".txt"))}
myf(5,6)

Upvotes: 2

JulianF
JulianF

Reputation: 141

You are using row and col as string in "res_row_col", you have to 'expend' them to write what is inside the variables.

Maybe something like that by cutting the string and using concatenation : "res_" . row . "_" . col

Upvotes: 1

Related Questions