I have a set of data where the response to a series of repeated questions is the outcome of interest. Because of this, I'd like to count the number of "I don't know" responses, grouping those counts by respondent ID, and append it as a new column. So basically, I have data that look like this:
ID | response |
---|---|
1 | Yes |
1 | I don't know |
2 | No |
2 | I don't know |
And I want them to look like this:
ID | response | idkcount |
---|---|---|
1 | Yes | 1 |
1 | I don't know | 1 |
2 | No | 1 |
2 | I don't know | 1 |
This is the code I've most recently written:
df$idkcount <- group_by(as_tibble(df$ID)) %>% count(df$response == "I don't know")
But I seem to get an error message no matter what I try with these two commands. What am I missing?