[R] export files - write.table

Marcus Leinweber leinweber at neuro.mpg.de
Mon Feb 13 17:31:47 CET 2006


Ana,

the following code may help:

teste="P:/test"
cc="pt"
yy="03"
data=matrix(1:12,3,4)

dir=paste(teste,cc,yy,sep="/")

# does directory already exist? if not, then create it
if (!is.null(try(setwd(dir),silent=TRUE))) {dir.create(dir,recursive=T)}

# write data to desired location 
write.table(data,file=paste(dir,"/",cc,yy,".txt",sep=""))

cheers,
marcus 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ana Quitério
> Sent: Monday, February 13, 2006 3:27 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] export files - write.table
> 
> Hi user
> 
> I have a question about export files.
> 
> I run my program for different countries and different years. 
> 
>  
> 
> For export files I do this in SAS:
> 
>  
> 
> (1) Path to data files
> 
> %let teste=C:\Documents and Settings\MEALQ\My Documents;
> 
>  
> 
> (2) Country code;
> 
> %let cc=pt;
> 
>  
> 
> (3) Survey year;
> 
> %let yy=03;
> 
>  
> 
> Output in: &teste\&cc\&yy\cc&yy.txt
> 
>  
> 
> How can I do a similar command in R?
> 
>  
> 
> Thanks in advance,
> 
>  
> 
> Ana Quiterio
> 
> Lisbon/Portugal
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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
>




More information about the R-help mailing list