Re: [R] sum in vector

2010-11-17 Thread Hadley Wickham
> rowsum(value, paste(factor1, factor2, factor3)) That is dangerous in general, and always inefficient. Imagine factor1 is c("a", "a b") and factor2 is ("b c", "c"). Use interaction with drop = T. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice Uni

Re: [R] sum in vector

2010-11-14 Thread Henrique Dallazuanna
Try this: rowsum(value, paste(factor1, factor2, factor3)) On Sun, Nov 14, 2010 at 5:21 PM, km wrote: > Hi all, > >> > >> On Sun, Nov 14, 2010 at 10:06 PM, Henrique Dallazuanna < > www...@gmail.com> wrote: > >>> Try this: > >>> > >>> rowsum(price, market) > does it work with multiple factor

Re: [R] sum in vector

2010-11-14 Thread lgpeco
thx all for help this function works fine aggregate(price,list(market),sum) i also find another one sapply(x, function) -- View this message in context: http://r.789695.n4.nabble.com/sum-in-vector-tp3041661p3042089.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] sum in vector

2010-11-14 Thread km
Hi all, >> >> On Sun, Nov 14, 2010 at 10:06 PM, Henrique Dallazuanna >> wrote: >>> Try this: >>> >>>  rowsum(price, market)  does it work  with multiple factors/groups ?  using multiple factors such as c(factor1,factor2,factor3,...) as second arg with  rowsum() doesnt seem to work!  am i miss

Re: [R] sum in vector

2010-11-14 Thread Feng Mai
to be more general you can also use aggregate: aggregate(price,list(market),sum) Henrique Dallazuanna wrote: > > Try this: > > rowsum(price, market) > > On Sun, Nov 14, 2010 at 10:02 AM, lgpeco wrote: > >> >> hy guys i have one question :) >> >> i have two vectors markets and price >> >>

Re: [R] sum in vector

2010-11-14 Thread Henrique Dallazuanna
Try this: rowsum(price, market) On Sun, Nov 14, 2010 at 10:02 AM, lgpeco wrote: > > hy guys i have one question :) > > i have two vectors markets and price > > market <- c(1, 5, 7, 9, 9, 6, 5, 4, 4, 3, 1, 2, 1) > price <- c(100, 20, 30, 10, 50, 23, 23, 33, 96, 6, 4, 38, 96) > i would like sum

Re: [R] sum in vector

2010-11-14 Thread John Kane
ice) library(reshape2) yy <- melt(xx, id=1) dcast(yy, market ~ variable, sum) - --- On Sun, 11/14/10, lgpeco wrote: > From: lgpeco > Subject: [R] sum in vector > To: r-help@r-project.org > Received: Sunday, November 14, 201

Re: [R] sum in vector

2010-11-14 Thread Alexx Hardt
Am 14.11.2010 13:02, schrieb lgpeco: hy guys i have one question :) i have two vectors markets and price market<- c(1, 5, 7, 9, 9, 6, 5, 4, 4, 3, 1, 2, 1) price<- c(100, 20, 30, 10, 50, 23, 23, 33, 96, 6, 4, 38, 96) i would like sum prices: market 1: (100+4+96), market 2: (38),..., market 9: (1

Re: [R] sum in vector

2010-11-14 Thread Andrew Dolman
tapply(price, market, sum) andydol...@gmail.com On 14 November 2010 13:02, lgpeco wrote: > > hy guys i have one question :) > > i have two vectors markets and price > > market <- c(1, 5, 7, 9, 9, 6, 5, 4, 4, 3, 1, 2, 1) > price <- c(100, 20, 30, 10, 50, 23, 23, 33, 96, 6, 4, 38, 96) > i would

[R] sum in vector

2010-11-14 Thread lgpeco
hy guys i have one question :) i have two vectors markets and price market <- c(1, 5, 7, 9, 9, 6, 5, 4, 4, 3, 1, 2, 1) price <- c(100, 20, 30, 10, 50, 23, 23, 33, 96, 6, 4, 38, 96) i would like sum prices: market 1: (100+4+96), market 2: (38),..., market 9: (10+50) ao i would like get this resul