I want to count the number of occurrences of a factor in a data frame. For example, to count the number of events of a given type in the code below:
library(plyr
Using dplyr library
library(dplyr)
data <- data.frame(level = c('A', 'A', 'B', 'B', 'B', 'C'),
value = c(1:6))
data %>%
group_by(level) %>%
summarize(count = n()) %>%
View
If you choose also to perform mean, min, max operations, try this
data %>%
group_by(level) %>%
summarise(count = n(), Max_val = max(value), Min_val = min(value)) %>%
View