I have a text file (76 rows) in CSV format containing following columns. Date contains the range of years (2003 - 2012 in this case) and ID contains the year of every row.
Date ID values
2003-06-07 00:00:00 1697144#6_2003 240
2004-01-01 00:00:00 1697144#6_2004 240
2005-05-27 00:00:00 1697149#6_2005 240
2006-01-01 00:00:00 1697149#6_2006 240
2007-01-01 00:00:00 1697149#6_2007 240
2008-01-01 00:00:00 1697149#6_2008 240
2009-01-01 00:00:00 1697149#6_2009 240
2010-01-01 00:00:00 1697149#6_2010 240
2011-01-01 00:00:00 1697149#6_2011 240
2012-01-01 00:00:00 1697149#6_2012 240
2003-06-07 00:00:00 1697158#6_2003 240
2004-01-01 00:00:00 1697158#6_2004 240
2003-06-07 00:00:00 1697163#6_2003 240
Using R, I would like to break this text file into multiple files of each year so that every file (for example: my_file_2003.csv) contains unique records (date, id and values) of that specific year only. This question (Stack Overflow) demonstrates how to split R dataframe into multiple files. Also this link demonstrates splitting large CSV files but in my case I need to merge all records of a specific year into a single file. Being a newbie to R, can someone help me how to break this single text file into multiple files of each year? I am using R version 3.2.3 on Windows 7 (x64).