Hi - does anyone know if there's a way to apply a count function to a filter function on the fly?
For example - instead of this:
mtcars %>%
filter(cyl==6) %>%
nrow()
is something like this possible:
mtcars %>%
nrow(filter(cyl==6))
The reason I'm asking is because I want to use this in mutate to add a column that returns a count of the number of filtered rows i.e. let's say add a column called "num_six_cyl" where the count of six cylinder cars repeats for each row.
If anyone knows DAX, this would be the equivalent of a CALCULATE function where you could put 'cyl = 6' in the filters section of the formula.