I would like to add the values of one column grouping them by two columns. I found how to do this on one column, but could not figure out how to do this on two columns. For example if I have the following data frame:
x=c("a","a", "b", "b","c", "c","a","a","b","b","c","c", "a", "a","b","b", "c", "c")
y=c(1:18)
q=c("M","M","M", "M","M","M","W","W","W","W","W","W","F","F","F","F","F","F")
df<-data.frame(x,y,q)
I would like to add the values in y column across x and q, so that I have a new data frame like this one
x=c("a","a", "b", "b","c", "c","a","a","b","b","c","c", "a", "a","b","b", "c", "c")
y=c(3,7,11,15,19,23,27,31,35)
q=c("M","M","M","W","W","W","F","F","F")
d<-data.frame(x,y,q)