[R] How to create a time series object with time only (no date)

Joshua Ulrich josh.m.ulrich at gmail.com
Sun Dec 21 16:20:25 CET 2014


On Sun, Dec 21, 2014 at 7:59 AM, ce <zadig_1 at excite.com> wrote:
>
> Thanks Joshua,
>
> Would you kindly explain if I have an xts array with different dates how I change all dates to 1970-01-01 without touching the time ? I tried with indexFormat without success. indexFormat(s) <- "1970-01-01 %H:%M:%S" . when I plot a graph it still shows original dates.

You can't just change how the data are printed.  You have to actually
change the underlying data.  Here's one example of how you could do
that:

x <- xts(1:5, .POSIXct(1:5+86400*1:5, tz="UTC"))
index(x) <- as.POSIXct(paste("1970-01-01",
  format(index(x), "%H:%M:%S")), tz="UTC")

Note that you should ensure your timezone is UTC, GMT, or any timezone
that doesn't have daylight saving time.  Otherwise you might have
instances in your data where certain hours either do not exist or
exist twice.

> ce
>
>
> -----Original Message-----
> From: "Joshua Ulrich" [josh.m.ulrich at gmail.com]
> Date: 12/21/2014 12:53 AM
> To: "ce" <zadig_1 at excite.com>
> CC: "R-Help" <r-help at r-project.org>
> Subject: Re: [R] How to create a time series object with time only (no date)
>
> On Dec 20, 2014 11:11 PM, "ce" <zadig_1 at excite.com> wrote:
>>
>>
>> Dear all,
>>
>> I want to create a time series object from 00:00:00 to 23:59:00 without dates ?
>> I cant figure it out with xts ?
>>
> You cant create an xts object without a date in the index. If the date doesnt matter, you can just set it to 1970-01-01 (or any other day).
>> ce
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
>



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-help mailing list