You can do it more concisely with n()
:
library(dplyr)
dat %>% group_by(cat) %>% filter(n() == 5)
More Related Contents:
- R: How to filter/subset a sequence of dates
- Filtering rows in R unexpectedly removes NAs when using subset or dplyr::filter
- Filter data.frame rows by a logical condition
- Subset data frame based on number of rows per group
- Why is `[` better than `subset`?
- Filter rows which contain a certain string
- Filtering a data frame by values in a column [duplicate]
- Opposite of %in%: exclude rows with values specified in a vector
- Subset / filter rows in a data frame based on a condition in a column
- R spreading multiple columns with tidyr [duplicate]
- Filtering a data frame on a vector [duplicate]
- Subset of rows containing NA (missing) values in a chosen column of a data frame
- dplyr filter with condition on multiple columns
- How to add a cumulative column to an R dataframe using dplyr?
- Get last row of each group in R [duplicate]
- R – add column that counts sequentially within groups but repeats for duplicates
- Change value of variable with dplyr
- Using grep to help subset a data frame
- Merge rows in a dataframe where the rows are disjoint and contain NAs
- Calculate group mean while excluding current observation using dplyr
- Filter data frame rows based on values in vector
- mutate_each / summarise_each in dplyr: how do I select certain columns and give new names to mutated columns?
- Join two data frames in R based on closest timestamp
- Selecting columns in R data frame based on those *not* in a vector
- How to filter data without losing NA rows using dplyr
- Return df with a columns values that occur more than once [duplicate]
- Undefined columns selected when subsetting data frame
- How to dplyr rename a column, by column index?
- Override column types when importing data using readr::read_csv() when there are many columns
- Adding column if it does not exist