I have a dataset containing 100000 rows of data. I tried to do some countif operations in Excel, but it was prohibitively slow. So I am wondering if this kind o
Table is the obvious choice, but it returns an object of class table which takes a few annoying steps to transform back into a data.frame
So, if you're OK using dplyr, you use the command tally:
library(dplyr)
df = data.frame(sex=sample(c("M", "F"), 100000, replace=T), occupation=sample(c('Analyst', 'Student'), 100000, replace=T)
df %>% group_by_all() %>% tally()
# A tibble: 4 x 3
# Groups: sex [2]
sex occupation `n()`
1 F Analyst 25105
2 F Student 24933
3 M Analyst 24769
4 M Student 25193