I'm trying now for some days to find a solution to something really simple, with no luck. Here it is:
- I've got a data frame with a row called
RESPONSE. - I'm subsetting condition A and then grouping by
Subject. - I'd like to count the sum of the cases per Subject where
RESPONSE==44andRESPONSE==77. However, not every subject has these, so for some subjects this sum should be 0.
I tried various commands, incl. summarise, count, filter. But I either get an aggregate of the cases overall for everyone, or it drops participants who don't have 77 or 44 (as opposed to assigning them a 0).
I imagine the code should look something like:
Condition_A <- subset(df, Condition=="A") %>%
group_by(Subject) %>%
sum(df$RESPONSE==77 | df$RESPONSE==44)
I see other people using sum the same way but I get an error that all my variables need to be numeric, and the row RESPONSE itself is.
I'd be extremely grateful for any help here. Thank you.