title: R count weights ~ similar but dif question
body: <pre><code>set.seed(1)
  data = data.frame("person"=c(1:100),
                    "group"=c(sample(1:2,100,r=T)),
                    "type"=c(sample(1:3,100,r=T)),
                    "value"=c(sample(20:40,100,r=T)),
                    "weight"=c(sample(100:300,100,r=T)),
                    "score" = c(sample(1:3,100,r=T)))
  </code></pre>
  
  <p>What I aim to do is first aggregate by "value" and then apply the "weight" to the score. Desired output is like the following----</p>
  
  <pre><code>want = data.frame("value"=sort(rep(unique(data$value),6)),
                    "group"=rep(1:2,63),
                    "type"=rep(1:3,42),
                    "score"=sample(1:3,126,r=T))
  </code></pre>
  
  <p>However I aim to have the "want" data frame include the WEIGHTED score variable. </p>
  
  <p>--</p>
  
  <p>Another example inspired from @Maurits Evers thank you. I think this is what I aim for.</p>
  
  <pre><code>data = data.frame("person"=c(1,2,3,4,5,6,7,8,9,10),
                    "group"=c(1,1,1,2,2,1,1,2,2,2),
                    "type"=c(1,1,2,3,3,3,3,2,2,1),
                    "value"=c(5,6,5,5,8,9,12,12,7,6),
                    "score"=c(3,3,2,3,3,2,1,1,1,1),
                    "weight"=c(100,200,100,200,150,300,100,200,200,300))
  data$scoreWEIGHT = data$score * data$weight
  aggregate(data$scoreWEIGHT, by=list(Category=data$value), FUN=sum)
  #but i aim to use the count function ()
  </code></pre>