[R] Time problems (POSIXct)
Research
risk2009 at ath.forthnet.gr
Tue May 25 13:26:41 CEST 2010
Thanks Gabor,
I suppose that in the example below, you can convet Date to POSIXct as
well, can't you?
Best,
Costas
On 20/05/2010 18:08, Gabor Grothendieck wrote:
> The warning message does tell you exactly what was wrong. You are
> trying to merge zoo objects that have two different index classes.
> The first is "POSIXct" and the second is "Date" class. Next time
> please provide your data in reproducible form
> as shown here:
>
>
>> library(zoo)
>> z1<- zoo(1:6, as.Date(c("1950-01-05", "1950-01-06", "1950-01-09",
>>
> + "1950-01-10", "1950-01-11", "1950-01-12")))
>
>> z2<- zoo(c(16.66, 16.85, 16.93, 16.98, 17.08, 17.03),
>>
> + as.POSIXct(c("1950-01-03, GMT", "1950-01-04, GMT", "1950-01-05, GMT",
> + "1950-01-06, GMT", "1950-01-09 GMT", "1950-01-10 GMT")))
>
>> merge(z1, z2 = aggregate(z2, as.Date, identity))
>>
> z1 z2
> 1950-01-03 NA 16.66
> 1950-01-04 NA 16.85
> 1950-01-05 1 16.93
> 1950-01-06 2 16.98
> 1950-01-09 3 17.08
> 1950-01-10 4 17.03
> 1950-01-11 5 NA
> 1950-01-12 6 NA
>
>>
>> # or
>> z2.Date<- z2
>> time(z2.Date)<- as.Date(time(z2.Date))
>>
>> merge(z1, z2.Date)
>>
> z1 z2.Date
> 1950-01-03 NA 16.66
> 1950-01-04 NA 16.85
> 1950-01-05 1 16.93
> 1950-01-06 2 16.98
> 1950-01-09 3 17.08
> 1950-01-10 4 17.03
> 1950-01-11 5 NA
> 1950-01-12 6 NA
>
>
> On Thu, May 20, 2010 at 10:48 AM, Research<risk2009 at ath.forthnet.gr> wrote:
>
>> Hello,
>>
>> I have a zoo time series object (say a) with the following time
>> stamp/format
>>
>>
>>
>> [1] "1950-01-03 GMT" "1950-01-04 GMT" "1950-01-05 GMT" "1950-01-06 GMT"
>> [5] "1950-01-09 GMT" "1950-01-10 GMT"
>>
>>
>> and another (say b) with
>>
>>
>> [1] "1950-01-05" "1950-01-06" "1950-01-09" "1950-01-10" "1950-01-11"
>> [6] "1950-01-12"
>>
>>
>> I want to merge these series but when I try:
>>
>>
>>
>>> head(merge(a, b ))
>>>
>> a b
>> 1950-01-03 02:00:00 16.66 NA
>> 1950-01-04 02:00:00 16.85 NA
>> 1950-01-05 02:00:00 16.93 NA
>> 1950-01-06 02:00:00 16.98 NA
>> 1950-01-09 02:00:00 17.08 NA
>> 1950-01-10 02:00:00 17.03 NA
>> Warning message:
>> In merge.zoo(a, b) :
>> Index vectors are of different classes: POSIXt Date
>>
>>>
>> Anybody can help? I tried as.POSIXct(a,tz="GMT") but it doesn't seem to
>> work....
>>
>> Many thanks in advance!
>>
>> Costas
>> _
>> platform i386-pc-mingw32
>> arch i386
>> os mingw32
>> system i386, mingw32
>> status
>> major 2
>> minor 10.1
>> year 2009
>> month 12
>> day 14
>> svn rev 50720
>> language R
>> version.string R version 2.10.1 (2009-12-14)
>>
>>>
>> ______________________________________________
>> 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.
>>
>>
> __________ Information from ESET Smart Security, version of virus signature database 5133 (20100520) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
More information about the R-help
mailing list