[R] xts time series object removing time and leaving just the date
arun
smartpink111 at yahoo.com
Thu Mar 7 20:09:17 CET 2013
Hi,
Try this:
library(xts)
Date1<- seq(as.POSIXct("2012-09-10 02:15:00",format="%Y-%m-%d %H:%M:%S"), as.POSIXct("2012-09-12 02:15:00",format="%Y-%m-%d %H:%M:%S"), by="min")
length(Date1)
#[1] 2881
set.seed(15)
value<- rnorm(2881)
xt1<-xts(value,order.by=Date1)
res<-apply.daily(xt1,sum)
res1<- res
res
# [,1]
#2012-09-10 23:59:00 19.64393
#2012-09-11 23:59:00 -81.62702
#2012-09-12 02:15:00 11.98883
index(res)<-as.Date(unlist(lapply(strsplit(as.character(index(res))," "),function(x) x[1])))
res
# [,1]
#2012-09-10 19.64393
#2012-09-11 -81.62702
#2012-09-12 11.98883
#or
index(res1)<-as.Date(gsub("\\s+.*","",index(res1)))
res1
# [,1]
#2012-09-10 19.64393
#2012-09-11 -81.62702
#2012-09-12 11.98883
A.K.
----- Original Message -----
From: Douglas Karabasz <douglas at sigmamonster.com>
To: r-help at r-project.org
Cc:
Sent: Thursday, March 7, 2013 1:42 PM
Subject: [R] xts time series object removing time and leaving just the date
I have and XTS time series object that has date and time. I started with 1
minute data and used apply.daily(x, sum) to sum the data to one cumulative
value. This function works just fine however it leaves a time for the last
summed value which looks like this 2006-07-19 14:58:00. I need to just have
the date and to remove the time value of 14:58:00 just leaving the date
value of 2006-07-19 . I want to keep the xts object otherwise intact. Is
this possible?
Thank you,
Douglas
[[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.
More information about the R-help
mailing list