How to count the number of observations in R like Stata command count
The with function will let you use shorthand column references and sum will count TRUE results from the expression(s). As @mnel pointed out, you can also do: The benefit of that is that you can do: And, the behaviour matches Stata’s count almost exactly (syntax notwithstanding).