[R] change the name of file

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Mon Jul 24 11:31:18 CEST 2006


Do you mean write.table instead of Write() ? Try 

 fn <- paste("Data_", i, ".txt", sep="")
 write.table( t(x), file=fn, sep="\t" )

Regards, Adai


On Mon, 2006-07-24 at 11:06 +0200, Robert Mcfadden wrote:
> Dear R Users,
> Is it possible to make file names dependent on a changing variable?
> For instance. I generate random numbers in a loop and at each iteration I
> want data to write to file (I do not want to write everything in one file
> using 'append'):
> 
> for (i in 1:50){
> x<-matrix(runif(100, min=0,max=1),nrow=5,ncol=20)
> Write(t(x),file="Data_i.txt",ncolumns=5,sep="\t") 
> }   
> 
> Of course file name Data_i.txt will be the same for changing i,
> unfortunately. 
> 
> Any suggestion would be appreciate
> Robert
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list