Hi listers, I have a simple doubt... I need to manipulate the data base as: var1 var2 7 0.1 7 0.1 8 0.12 10 0.15 12 0.18 20 0.31 I would like to aggregate the equal cases as var1 making the sum of var2... I would get... var1 var2 7 0.2 8 0.12 10 0.15 12 0.18 20 0.31 Thanks in advance, Marcio -- View this message in context: http://www.nabble.com/Sum-according-observation-tp25510566p25510566.html Sent from the R help mailing list archive at Nabble.com.
Try this: with(DF, tapply(var2, var1, sum)) On Fri, Sep 18, 2009 at 12:18 PM, MarcioRibeiro <mestat at pop.com.br> wrote:> > Hi listers, > I have a simple doubt... > I need to manipulate the data base as: > > var1 var2 > 7 ? ? ?0.1 > 7 ? ? ?0.1 > 8 ? ? ?0.12 > 10 ? ?0.15 > 12 ? ?0.18 > 20 ? ?0.31 > > I would like to aggregate the equal cases as var1 making the sum of var2... > I would get... > > var1 var2 > 7 ? ? ?0.2 > 8 ? ? ?0.12 > 10 ? ?0.15 > 12 ? ?0.18 > 20 ? ?0.31 > > Thanks in advance, > Marcio > -- > View this message in context: http://www.nabble.com/Sum-according-observation-tp25510566p25510566.html > Sent from the R help mailing list archive at Nabble.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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
?aggregate with(xx,aggregate(var2, list(var1=var1),sum) --- On Fri, 9/18/09, MarcioRibeiro <mestat at pop.com.br> wrote:> From: MarcioRibeiro <mestat at pop.com.br> > Subject: [R] Sum according observation > To: r-help at r-project.org > Received: Friday, September 18, 2009, 11:18 AM > > Hi listers, > I have a simple doubt... > I need to manipulate the data base as: > > var1 var2 > 7? ? ? 0.1 > 7? ? ? 0.1 > 8? ? ? 0.12 > 10? ? 0.15 > 12? ? 0.18 > 20? ? 0.31 > > I would like to aggregate the equal cases as var1 making > the sum of var2... > I would get... > > var1 var2 > 7? ? ? 0.2 > 8? ? ? 0.12 > 10? ? 0.15 > 12? ? 0.18 > 20? ? 0.31 > > Thanks in advance, > Marcio > -- > View this message in context: http://www.nabble.com/Sum-according-observation-tp25510566p25510566.html > Sent from the R help mailing list archive at Nabble.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. >__________________________________________________________________ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com.