I am working with several colleagues to code information in studies about language education. I want to create a function that summarizes the counts for each coding decision (0 = No, 1 = Yes, CT = Can't tell, and NS = Not sure!) in a column of a df. In the df below, the first column is the name of a study. Columns 2:4 are variables that contain codes.
In the end, I'm trying to write a function that tells me how many 0's, 1's, CT's, etc. were coded for each item or column in a df after the study name. I tried saving the output as a list, but I'm just not having any luck. I think I'm missing something simple. Help, anyone?
df <- tibble(
StudyName = c("Wash_2001", "Mal_1999", "Jane_2002", "Zoey_1976"),
Item1 = c(1, 1, 0, 1),
Item2 = c(0, 0, 0, "CT"),
Item3 = c(1, 0, 1, "NS")
)
df %>% # I'm hoping each element in the list will have
count(Item1) # this for each column in the df.
Excellent! Thanks a bunch! One more quick, follow-up question: Is there a way to group that by StudyName? I have a hierarchical spreadsheet in which one StudyName can have multiple rows. I would love to use the above function to obtain not the total number of rows for each code but collapse rows by StudyName. Is that possible? Thanks, again.