I have a dataframe like the following in R:
df <- matrix(c('A','A','A','A','B','B','B','B','C','C','C','C',4,6,8,2,2,7,2,8,9,1,2,5),ncol=2)
For each row of this dataframe, I want to include the total value for each class (A,B,C) so that the dataframe will look this this:
df <- matrix(c('A','A','A','A','B','B','B','B','C','C','C','C',4,6,8,2,2,7,2,8,9,1,2,5,20,20,20,20,19,19,19,19,17,17,17,17),ncol=3)
What's a way I could accomplish this?
Thanks in advance for your help.