New here, struggling with what (I think) is a bear of a problem.
I have a dataframe containing 16 variables and 293 observations. Each variable is a condition a respondent was asked about, and the cell value is "Yes", "No", or "Unknown" - these were coded in the dataframe as 1, 0, and 2 respectively.
I took this dataframe and ran it through gather() - which gave me a dataframe consisting of 4688 observations and 2 variables - Condition, and Value - where Condition is text corresponding to the condition the respondent was asked about and Value is the person's response (0, 1, or 2).
I then recoded the Value column replacing 0 with "No", 1 with "Yes", and 2 with "Unknown".
(I can't find how to insert R code so I apologize for the following jankiness)
So the dataframe looks like this:
What I can't figure out is how to get to this programmatically (if the above is an example):
Condition Value Count
A No 1
A Yes 2
A Unknown 1
B Yes 1
I've tried group_by(Condition) %>% summarize(n()) but that just gives me the total numbers of each condition - not what I'm looking for.
I tried using split-apply-combine methods... but I don't know what I'm missing.
Sidenote: I managed to get to what I wanted by manually using df %>% count(VARIABLE), and manually re-running this line 16 times, each time changing the name of the variable to what I wanted... but obviously that sort of solution doesn't scale up.
Please help! And thank you ^.^