[R] Merge data frames but with a twist.
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Aug 27 16:27:26 CEST 2009
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