r - count the number of times a number (factor) occurs within each group -


with reproducible data below,

dat <- data.frame(bin = rep(1:4, each = 50),                    number = sample(5, 200, replace = t, prob = c(1,1,1,2,3)))   > head(dat)   bin number 1   1      3 2   1      5 3   1      4 4   1      5 5   1      5 6   1      1 

i want count number of times each number occurs within each bin, preferably using dplyr. said differently, how many occurrences of each level of number in each bin?

thanks!

dplyr has count function this.

dat %>% count(number,bin) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -