I wanted to know if there was a more efficient way to add a tally to a dataset in R.
Using the mpg dataset, this is how I do it using the mpg dataset as an example.
mpg %>%
group_by(manufacturer) %>%
count() %>%
right_join(
mpg
)
So essentially, I want a count of the number of unique observations in the manufacturer column. It works fine as this is quite a small dataset, but I'm working with datasets with over 100k observations and wanted to find a better way to do it than to join in this way.
To give context, the number of unique observations are used as denominators for subsequent analyses.