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.
[[alternative HTML version deleted]]
Hello,
You can try the following:
x <- read.table(text="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")
colnames(x) <- c('Date','Time','Value')
y <-
c('00:00:00','01:00:00','02:00:00','03:00:00','04:00:00','05:00:00')
idx <- is.element(x$Time, y)
x[idx,]
Hope this help.
Pascal
Le 01/08/2012 15:48, ??????????? ????????? a ?crit :> 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.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
Hi,
Try this:
dat1<- read.table(text="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
",header=FALSE,sep="")
?dat2<-data.frame(time=c("00:00:00","01:00:00","05:00:00"))
dat3<-merge(dat2,dat1)
?dat3<-dat3[,c(2,1,3)]
?dat3<-dat3[order(dat3$date),]
rownames(dat3)<-1:nrow(dat3)
dat3
?dat3
??????? date???? time 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
4 2000-02-05 00:00:00?? 1.0
5 2000-02-05 01:00:00?? 1.0
6 2000-02-05 05:00:00?? 3.6
A.K.
----- Original Message -----
From: ??????????? ????????? <vasilchenko.a.p at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, August 1, 2012 2:48 AM
Subject: [R] Date period
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.
??? [[alternative HTML version deleted]]
______________________________________________
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.
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()
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.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.