[R] Help with speed (replacing the loop?)
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Wed Jan 11 17:30:33 CET 2012
It is common that performance problems are addressed by using more memory. If your algorithm needs to join those tables and do calculations, then you can either pay the piper in memory (usually the most appropriate answer) or you can reinvent those optimized algorithms in a compiled language and figure out how to thread them together to minimize memory use (a dangerous course of action). Try working on chunks of xx? Or getting more memory in your computer?
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:
>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
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list