[R] Add 1 week to date with hours included for subset

emorway emorway at engr.colostate.edu
Fri May 14 05:25:22 CEST 2010


Forum, 

I've got hourly data for roughly 5 months of time that I want to subset into
successive weeks.  The first two elements of the dataset are

well.80.2$date[1]
>[1] 6/12/2000 2:00
>9256 Levels: 10/1/2001...

well.80.2$date[2]
>[1] 6/12/2000 3:00
>9256 Levels: 10/1/2001....

and so on until mid-october.  I've been able to add 1 week the first element
with the following:

as.POSIXlt(paste(as.character(as.Date(well.80.2$date[1],"%m/%d/%Y
%H:%M")+7),as.character(format(strptime(well.80.2$date[1],"%m/%d/%Y
%H:%M"),"%H:%M")),sep=" "))
>[1] "2000-06-19 02:00:00"
  
What I've been unable to do is then use this for comparative purposes in the
subset command, something to the effect of:

contin.80.2<-subset(well.80.2,well.80.2$date>=well.80.2$date[1]) &
well.80.2$date <
as.POSIXlt(paste(as.character(as.Date(well.80.2$date[1],"%m/%d/%Y
%H:%M")+7),as.character(format(strptime(well.80.2$date[1],"%m/%d/%Y
%H:%M"),"%H:%M")),sep=" "))

If there is an easier way to parse the dataset into weekly bins taking into
consideration the hours, I'm open to suggestions.

Thank you.

-- 
View this message in context: http://r.789695.n4.nabble.com/Add-1-week-to-date-with-hours-included-for-subset-tp2216062p2216062.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list