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

php - mysql multiple keyword search in any order -

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

unity3d - Problems porting a GLSL shadertoy shader to unity -