Hi, For very large matrices, is this the most efficient way to add two variables together? ############################# attach(attenu) new<-rowSums(cbind(mag, station)) ############################# Also, could I be directed to some resources for working with very large datasets? Thanks
Probably more efficient if you remove the 'cbind' which would create a combined matrix. Use the following: rowSums(mag) + rowSums(station) On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane <tzygmund at googlemail.com> wrote:> Hi, > > For very large matrices, is this the most efficient way to add two > variables together? > > ############################# > attach(attenu) > new<-rowSums(cbind(mag, station)) > ############################# > > Also, could I be directed to some resources for working with very > large datasets? > > Thanks > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
with(attenu, mag + as.numeric(station)) is nearly twice as fast:> system.time(for(i in 1:1000) with(attenu, mag + as.numeric(station)))user system elapsed 0.05 0.02 0.06> system.time(for(i in 1:1000) rowSums(cbind(mag, station)))user system elapsed 0.09 0.00 0.10 See ?system.time, ?Rprof and http://code.google.com/p/rbenchmark/ for timing commands. On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane <tzygmund at googlemail.com> wrote:> Hi, > > For very large matrices, is this the most efficient way to add two > variables together? > > ############################# > attach(attenu) > new<-rowSums(cbind(mag, station)) > ############################# > > Also, could I be directed to some resources for working with very > large datasets? > > Thanks > > ______________________________________________ > 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. >
Thank you Gabor (& Henrique)! On Sun, Sep 27, 2009 at 3:26 PM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> with(attenu, mag + as.numeric(station)) > > is nearly twice as fast: > >> system.time(for(i in 1:1000) with(attenu, mag + as.numeric(station))) > ? user ?system elapsed > ? 0.05 ? ?0.02 ? ?0.06 > >> system.time(for(i in 1:1000) rowSums(cbind(mag, station))) > ? user ?system elapsed > ? 0.09 ? ?0.00 ? ?0.10 > > See ?system.time, ?Rprof and http://code.google.com/p/rbenchmark/ > for timing commands. > > On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane > <tzygmund at googlemail.com> wrote: >> Hi, >> >> For very large matrices, is this the most efficient way to add two >> variables together? >> >> ############################# >> attach(attenu) >> new<-rowSums(cbind(mag, station)) >> ############################# >> >> Also, could I be directed to some resources for working with very >> large datasets? >> >> Thanks >> >> ______________________________________________ >> 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. >> >