How to do this question in R without using loop? : <p>Let's say I have a dataframe like this:</p>

<pre><code>df=data.frame("A"=factor(c(1,2,1,4,2)), "date"=factor(c("1999","2000","1999","2001","2001")), "value"=c(10,20,30,40,50))
</code></pre>

<p>I need to sum the values in the column "value" if they have the same "A" and "date".
So what I need is a dataframe like this:</p>

<pre><code>dfnew=data.frame("A"=factor(c(1,2,1,4,2)), "date"=factor(c("1999","2000","1999","2001","2001")), "value"=c(10,20,30,40,50), "sum"=c(40,20,40,40,50))
</code></pre>

<p>I can do it with a loop, but it is very slow since my dataset is big. Is there any way to do it faster?</p>
