[R] Merge data frames but with a twist.
ggrothendieck at gmail.com
Thu Aug 27 20:26:43 CEST 2009
The inconsistency arose in order to satisfy backward compatibility
while giving chron a direct way to use % codes.
chron used its own format specification so it would have been difficult
to add % codes there; however, as.chron, at the time, did not support a
format specification at all so it was still possible to add a format specifier
using % codes without disrupting existing code.
On Thu, Aug 27, 2009 at 2:21 PM, Stephen Tucker<brown_emu at yahoo.com> wrote:
> 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!
> ----- 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:
>>> 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
>>> zobj <- zoo(`mode<-`(t(mydf),"numeric"),
>>> as.chron(strptime(names(mydf)[-1],"%m/%d/%Y %I:%M %p")))
>> (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