[R] Merge data frames but with a twist.

Stephen Tucker brown_emu at yahoo.com
Thu Aug 27 20:21:23 CEST 2009


Ah, thanks always - 
I originally thought as.chron() was required to have all fields (m/d/y hh:mm:ss) as for chron() but I see that the former passes its 'format' argument to  as.POSIXct()
Good deal!
Stephen



----- Original Message ----
From: Gabor Grothendieck <ggrothendieck at gmail.com>
To: Stephen Tucker <brown_emu at yahoo.com>
Cc: Tony Breyal <tony.breyal at googlemail.com>; r-help at r-project.org
Sent: Thursday, August 27, 2009 7:27:26 AM
Subject: Re: [R] Merge data frames but with a twist.

On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tucker<brown_emu at yahoo.com> wrote:
> You may want to use the reshape package for this task:
>
>> library(reshape)
>> recast(DF3,Show ~ Datetime, id.var=names(DF3),value="Measure")
>       Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM
> 1   Firefly                   3                  1
> 2 Red Dwarf                   4                  2
>
> If you want to plot time series, you can do something like the following
>
>> mydf <- .Last.value ## save the output from above to mydf
>> library(zoo)
>> zobj <- zoo(`mode<-`(t(mydf),"numeric"),
>>             as.chron(strptime(names(mydf)[-1],"%m/%d/%Y %I:%M %p")))
>> plot(zobj)
>
> (zobj is a time series object of the zoo class)

Note that as.chron can take % codes directly so the as.chron portion
can be shortened to:

as.chron(names(mydf)[-1],"%m/%d/%Y %I:%M %p")




More information about the R-help mailing list