Tidyr how to spread into count of occurrence [duplicate]
This question already has an answer here: How do I get a contingency table? 6 answers Faster ways to calculate frequencies and cast from long to wide 4 answers Have a data frame like this other=data.frame(name=c("a","b","a","c","d"),result=c("Y","N","Y","Y","N")) How can I use spread function in tidyr or other function to get the count of result Y or N as column header like this name Y N a 2 0 b 0 1 Thanks These are a few ways of many to go about it: 1) With library dplyr , you can simply group things and count into the format needed: library(dplyr) other %>% group_by(name) %>% summarise(N =