[datatable-help] Join with roll

Matthew Dowle mdowle at mdowle.plus.com
Tue Sep 25 12:13:43 CEST 2012


Hi,
But roll rolls forward, not backwards. If you'd like the first value of
each group to be rolled backwards, then something like this first
(untested)? :
    helpdt[J(unique(ID)),Hr:=-Inf,mult="first"]
then when you join to the modified helpdt, the first item for each group
will appear to be rolled backwards.
Matthew

> Hi Matthew,
>
> A probably trivial problem, but cannot seem to sort this one out.
> I have a similar problem as described in SO
> 9http://stackoverflow.com/questions/10438969/fastest-way-to-add-rows-for
> -missing-values-in-a-data-frame): need to insert missing time points
> into a data.table and set the parameter value to NA while padding the
> grouping variables.
> I tried your solution but...that the timepoint that is missing in my
> data set is the first time point, therefore roll=TRUE does not work and
> I get NA's where I would like to get values for the grouping variables
>
> helpdt=data.table(cbind(expand.grid(Hr=c(1,2,4),Rep=c("a","b","c"),COND=
> c("L","M","H")),ID=rep(1:9,each=3),Value=9090))
> setkey(helpdt,ID,Hr)
> helpdt[CJ(unique(ID),c(0,1,2,4)),roll=TRUE]
>
> Thanks
> Patrick
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>




More information about the datatable-help mailing list