[R] Help with speed (replacing the loop?)

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Wed Jan 11 16:50:04 CET 2012


Thanks a lot, Steve. I have one question (below):


> ====
> library(data.table)
>
> ## your data
> xx <- data.table(group=c(rep("group1",5),rep("group2",5)),
>                 a=1:10, b=seq(10,100,by=10), key="group")
> yy <- data.table(group=c("group1","group2"), a=c(10,20), b=c(2,3),
>                 key="group")
>
> ## temp data.table to get your ducks in a row
> m <- merge(xx, yy, by="group", suffixes=c(".x", ".y"))


Dimitri: The step above (merge) - I was thinking of it but decided
against it because my xx already fills up tons of memory. When I merge
xx and yy that doubles the number of variables - I am afraid my memory
won't hold that much stuff...


> ## your answers will be in the aa and bb columns
> result <- transform(m, aa=a.x * a.y, bb=b.x * b.y)
>
> ====
>
> Truth be told, if you use normal data.frames, the code will look very
> similar to above, so you can try that, too.
>
> HTH,
> -steve
>
>
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact



-- 
Dimitri Liakhovitski
marketfusionanalytics.com



More information about the R-help mailing list