The station column has non numeric values, so you need convert to numeric before:
with(attenu, as.numeric(as.character(station)) + mag) On Sun, Sep 27, 2009 at 8:47 AM, tzygmund mcfarlane <tzygm...@googlemail.com> wrote: > Jim, > > Both my emails contained reproducible code (the first one wasn't > completely reproducible - it required one to know that "attenu" is a > base R dataset). > > Anyway, thanks for your help. > > On Sat, Sep 26, 2009 at 8:11 PM, jim holtman <jholt...@gmail.com> wrote: >> I assumed (since you did not provide reproducible code) that 'mag' was >> a matrix. If 'station' is a matrix, then >> >> mag + rowSums(station) >> >> will work. If that does not work, then you need to tell us what your >> data objects are. >> >> On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane >> <tzygm...@googlemail.com> wrote: >>> Hi Jim, >>> >>> I might be missing something but your command gives the error: >>> Error in rowSums(mag) : 'x' must be an array of at least two dimensions >>> >>> ############################# >>> data(attenu) >>> attach(attenu) >>> rowSums(mag) + rowSums(station) >>> attenu$new<-rowSums(cbind(mag, station)) >>> ############################# >>> >>> Thanks >>> >>> >>> On Sat, Sep 26, 2009 at 4:30 PM, jim holtman <jholt...@gmail.com> wrote: >>>> 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 >>>> <tzygm...@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@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? >>>> >>> >> >> >> >> -- >> Jim Holtman >> Cincinnati, OH >> +1 513 646 9390 >> >> What is the problem that you are trying to solve? >> > > ______________________________________________ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ R-help@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.