I've found similar queries listed on here, but none of them have been able to work for me. I have binary data listed in a data frame which I want to aggregate according to another variable. For example.
Data.frame (A & B are columns)
A B
1 23
0 7
0 23
0 7
1 4
I've tried the below (which worked when finding the mean) and get the following error message:
aggregate( A~B, data.frame, sum)
Error in FUN(X[[1L]], ...) : invalid 'type' (character) of argument
Ideally I would like an output which gives 23 = 1, 7 = 0, 4 = 1
Can anyone help me please?
Thanks in advance!