[R] Date period
David Winsemius
dwinsemius at comcast.net
Wed Aug 1 18:59:04 CEST 2012
On Aug 1, 2012, at 5:33 AM, Rui Barradas wrote:
> Hello,
>
> Try the following.
>
>
> dat <- structure(list(date = c("2000-01-05 00:00:00", "2000-01-05
> 01:00:00",
> "2000-01-05 05:00:00", "2000-01-05 06:00:00", "2000-01-05 07:00:00",
> "2000-01-05 08:00:00", "2000-01-05 09:00:00", "2000-01-05 10:00:00",
> "2000-01-05 11:00:00", "2000-02-05 00:00:00", "2000-02-05 01:00:00",
> "2000-02-05 05:00:00", "2000-02-05 06:00:00", "2000-02-05 07:00:00",
> "2000-02-05 08:00:00", "2000-02-05 09:00:00", "2000-02-05 10:00:00",
> "2000-02-05 11:00:00"), value = c(1, 1, 3.6, 3.6, 2.2, 2.2, 2.2,
> 2.2, 2.2, 1, 1, 3.6, 3.6, 2.2, 2.2, 2.2, 2.2, 2.2)), .Names =
> c("date",
> "value"), row.names = c(NA, -18L), class = "data.frame")
>
> library(chron) # needed for times()
I don't think you do need to use chron. Once the date-times are
available as POSIXt values, you can just use the formated times for
comparisons:
> dat$date <- as.POSIXct( dat$date)
> tm <- format(dat$date, format="%H:%M:%S")
> inx <- "00:00:00" <= tm & tm <= "05:00:00"
> dat[inx, ]
date value
1 2000-01-05 00:00:00 1.0
2 2000-01-05 01:00:00 1.0
3 2000-01-05 05:00:00 3.6
10 2000-02-05 00:00:00 1.0
11 2000-02-05 01:00:00 1.0
12 2000-02-05 05:00:00 3.6
--
David.
> dat$date <- as.POSIXct(dat$date)
> tm <- times(format(dat$date, format="%H:%M:%S"))
> inx <- times("00:00:00") <= tm & tm <= times("05:00:00")
> dat[inx, ]
>
> Hope this helps,
>
> Rui Barradas
> Em 01-08-2012 07:48, Васильченко Александр
> escreveu:
>> Hello
>> I have dataframe
>> How to remove dates in hourly time seriesThe example time series
>> likedate
>> value
>> 2000-01-05 00:00:00 1.0
>> 2000-01-05 01:00:00 1.0
>> 2000-01-05 05:00:00 3.6
>> 2000-01-05 06:00:00 3.6
>> 2000-01-05 07:00:00 2.2
>> 2000-01-05 08:00:00 2.2
>> 2000-01-05 09:00:00 2.2
>> 2000-01-05 10:00:00 2.2
>> 2000-01-05 11:00:00 2.2
>> 2000-02-05 00:00:00 1.0
>> 2000-02-05 01:00:00 1.0
>> 2000-02-05 05:00:00 3.6
>> 2000-02-05 06:00:00 3.6
>> 2000-02-05 07:00:00 2.2
>> 2000-02-05 08:00:00 2.2
>> 2000-02-05 09:00:00 2.2
>> 2000-02-05 10:00:00 2.2
>> 2000-02-05 11:00:00 2.2
>>
>> And I take interval for example from 00:00:00 to 05:00:00.
>> date value
>> 2000-01-05 00:00:00 1.0
>> 2000-01-05 01:00:00 1.0
>> 2000-01-05 05:00:00 3.6
>> 2000-02-05 00:00:00 1.0
>> 2000-02-05 01:00:00 1.0
>> 2000-02-05 05:00:00 3.6
>> Regards, Aleksander.
>>
>
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list