This function is implemented specifically for each data source and can only be used from within summarise(), mutate() and filter().

n()

Examples

if (require("nycflights13")) { carriers <- group_by(flights, carrier) summarise(carriers, n()) mutate(carriers, n = n()) filter(carriers, n() < 100) }
#> Source: local data frame [32 x 19] #> Groups: carrier [1] #> #> year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time #> <int> <int> <int> <int> <int> <dbl> <int> <int> #> 1 2013 1 30 1222 1115 67 1402 1215 #> 2 2013 11 3 1424 1430 -6 1629 1634 #> 3 2013 11 10 1443 1430 13 1701 1634 #> 4 2013 11 17 1422 1430 -8 1610 1634 #> 5 2013 11 25 1803 1759 4 2011 2017 #> 6 2013 11 30 1648 1647 1 1814 1811 #> 7 2013 6 15 1626 1635 -9 1810 1830 #> 8 2013 6 22 1846 1635 131 2107 1830 #> 9 2013 8 27 1755 1805 -10 1956 1953 #> 10 2013 8 28 2039 1805 154 2213 1953 #> # ... with 22 more rows, and 11 more variables: arr_delay <dbl>, carrier <chr>, #> # flight <int>, tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, #> # distance <dbl>, hour <dbl>, minute <dbl>, time_hour <dttm>