HAVE = data.frame(STUDENT = c(1,2,3,4),
YEAR = c(2020,2020,2021,2020),
SCORE1 = c(5,9,8,0),
TEST = c(7,11,3,9))
WANT = data.frame(STUDENT = c(1,2,3,4, 'ALL'),
YEAR = c(2020, 2020, 2021, 2020,NA),
SCORE1 = c(5,9,8,0,22),
TEST = c(7,11,3,9,30))
I have 'HAVE' and wish to create 'WANT' which does this: Add row to HAVE where STUDENT = 'ALL' and SCORE1 = sum up all values of SCORE and TEST = sum up all values of TEST.
I try this with no success:
WANT = rowbind(HAVE, data.frame(STUDENT = 'ALL', SCORE1 = sum(HAVE$SCORE1), TEST = sum(HAVE$TEST))
But is there a efficient DPLYR solution?