I'd like to add a series variables to a dataframe:
patent < c(1,2,2)
temp1 < c(TRUE,FALSE,FALSE)
temp2 < c(FALSE,TRUE,TRUE)
df < data.frame(patent,temp1,temp2)
df
patent temp1 temp2
1 TRUE FALSE
2 FALSE TRUE
2 FALSE TRUE
What I would like to do is to generate column sums for each temp var, by patent, in a loop / function / using dplyr / etc. Here is what I'm ultimately looking for:
patent temp1 temp2 new1 new2
1 TRUE FALSE 1 0
2 FALSE TRUE 0 2
2 FALSE TRUE 0 2
