[R] Writing "monthly" .txt or .csv files from a long time series

Thomas Barningham stbarningham at gmail.com
Tue Jun 17 14:00:44 CEST 2014

Dear R users,

I have a .txt file of time series data from the middle of 1999 through
to the end of 2012. There are two columns in the file, the first is a
decimal date, the second is an atmospheric tracer value and looks like

Date  APO
1999.47945560  -168.48
1999.47948410  -158.08
1999.47951270  -163.79
1999.47956990  -164.38
1999.47959850  -173.94
1999.47962700  -161.92
1999.47965560  -154.36
1999.47968420  -147.55
1999.47971280  -157.06
1999.47974140  -151.21
1999.47976990  -141.63
1999.47979850  -147.97

What I'd now like to do is write new .txt (or .csv) files based on the
month of the year so that I have separate text files for Jan, Feb, Mar
etc for each year 1999, 2000, 2001 etc. using either the write.table
or write.csv function. Is there an easy way to do this in R?

Google key word searches have not been fruitful and the only other way
I can see to do this is "manually" in excel, which would take a long
time. I'm hoping there's a neat bit of code to do this.

Many thanks

Thomas Barningham
Centre for Ocean and Atmospheric Sciences
School of Environmental Sciences
University of East Anglia
Norwich Research Park

More information about the R-help mailing list