[R] removing data based on date pairs in a separate data frame

Thomas Barningham stbarningham at gmail.com
Mon Feb 29 16:20:52 CET 2016


Dear R users,

I have two data frames.

The first contains a date/time column and the concentration of a species:

head(mydata)
                         date                species
1      2016-01-31 23:59:53	-559.17		
2      2016-02-01 00:00:53	-556.68			
3      2016-02-01 00:01:53	-554.89		
4      2016-02-01 00:02:53	-556.72	
5      2016-02-01 00:03:53	-557.36		
6      2016-02-01 00:13:53	-561.42	


The second contains a list of start and end date pairs:

head(mydata_flag)
 	start_date	                end_date
1     2016-02-01 00:01:00	2016-02-01 00:03:00
2     2016-02-01 00:10:00	2016-02-01 00:15:00

I need to loop through all pairs of dates in the mydata_flag data
frame and then remove any data in the mydata data frame that is
between each of the date pairs.

The result for what I've presented here would look something like this:
                                  date       species
1	2016-01-31 23:59:53	-559.17		
2 	2016-02-01 00:00:53	-556.68			
3 	2016-02-01 00:03:53	-557.36		

I've searched high and low for answer to this. I know it's a
subsetting problem but I don't know how to approach it. Subset answers
tend to have one start end date pair and keep the data between the
dates. I need to remove data between the dates and I have a full data
frame of date/time pairs to consider. For background info: this is to
flag bad atmospheric data between times that there were known
instrumentation issues.

Thanks in advance,

Thomas

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



More information about the R-help mailing list