Let's say I have a dataframe like this:
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))
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:
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))
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?