[R] Append to files in loop

David Winsemius dwinsemius at comcast.net
Fri Mar 23 20:12:13 CET 2012


On Mar 23, 2012, at 2:19 PM, Luisin Galindo, PhD wrote:

> Hi ReXperts,
>
> I have a file 'XFile'

In your R workspace or not? Will assume this is an R dataframe.
With the same number of columns as the files to be updated? Will  
assume that the number of columns is the same and that you also want  
row.names.
What about separators? Will assume commas for purposes of example.

> that I wish to append to the end of file1, file2,
> file3, file4, and file 5. Can't figure out how to set up the loop.  
> Please
> help.

for (i in c("file1", 'file2', 'file3', 'file4', 'file 5') ){
      write.table( Xfile, file=i, sep="," , colnames=FALSE, append=TRUE)
      }

>
> 	[[alternative HTML version deleted]]
Please post in plain text.
>
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list