[R] get a dataframe subset based on time interval

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jun 25 15:44:06 CEST 2009


Try this:

DF <- data.frame(tt = ISOdate(2009, 1:12, 1), x = 1:12, y = 1:12)
st <- as.POSIXct("2009-05-01 00:00:00")
en <- as.POSIXct("2009-07-01 23:59:59")
DF[DF$tt > st & DF$tt < en, ]

If the data in DF is numeric you would probably be better off
using a zoo series than a data.frame in which case you can
use window.zoo:

library(zoo)
z <- read.zoo(DF, tz = "")
z0 <- window(z, st = st, end = en)
plot(z0)

See the three vignettes in the zoo package, ?read.zoo and ?window.zoo

On Thu, Jun 25, 2009 at 9:19 AM, Paulo E. Cardoso<pecardoso at netcabo.pt> wrote:
> Hi,
>
> I have a big dataframe with a POSIXct column and I'd like to extract a
> subset contained in a given time interval, from Date 1 to Date 2.
>
> ____________
> Paulo E. Cardoso
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list