Thank you both for response!
Enh, I never think about function though. Good.
My way is using 'aggregate' and 'merge' but it is a little bit trivial.
On Wed, Aug 11, 2010 at 9:13 PM, Dennis Murphy wrote:
> Hi:
>
> Try this from package plyr:
>
> library(plyr)
> # function to compute sum of sq
Hi:
Try this from package plyr:
library(plyr)
# function to compute sum of squares
f <- function(df) with(df, sum((tapply(value, type, sum)/sum(value))^2))
# apply it to each type of food:
ddply(data, .(food), conc = f(data))
food type value market_con
1 drink water 5 0.5987654
2 drin
Hi,
The code seems complicate, but it's understandable.
##
food=c('fruit','fruit','fruit','drink','drink','drink')
type=c('apple','apple','orange','water','soda','soda')
value=c(2,3,1,5,7,6)
data=data.frame(food,type,value)
share=c((2+3)/(2+3+1),5/6,1/6,5/(5+7+6),13/18,13/18)
market_con=c(re
Thank you for reminding me.
##
food=c('fruit','fruit','fruit','drink','drink','drink')
type=c('apple','apple','orange','water','soda','soda')
value=c(2,3,1,5,7,6)
data=data.frame(food,type,value)
share=c((2+3)/(2+3+1),5/6,1/6,5/(5+7+6),13/18,13/18)
market_con=c(rep(0.833^2+0.167^2,3),r
Hi Yi,
It would be helpful for others to provide a solution if you give your
formulas that calculating the value of share and concentration.
?apply will helps.
Regards,
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-calculate-the-concentration-
Hi, folks,
##
food=c('fruit','fruit','fruit','drink','drink','drink')
type=c('apple','apple','orange','water','soda','soda')
value=c(2,3,1,5,7,6)
data=data.frame(food,type,value)
share=c((2+3)/(2+3+1),5/6,1/6,5/(5+7+6),13/18,13/18)
market_con=c(rep(0.833^2+0.167^2,3),rep(0.278^2+0
6 matches
Mail list logo