I have a list of tables (quantity, year and month), and I want to filter rows corresponding to years. That is, I want to omit the last 4 lines of the approximate data frame that I give below, which relate to 2015, and get the remaining 60. Is it possible to do this with a single dplyr command?
I tried this:
df %>% group_by(year) %>% tally() %>% filter (n==12) %>% ungroup()
but I think ungroup is doing something different from what I want. Is it possible to do this with a single dplyr command?
df <- structure(list(amount = c(16365, 31850, 32230, 34177.75, 27900, 29650, 28846, 27300, 37115.31, 34130.38, 39676.1, 47244.44, 3500, 25425.48, 22628.43, 30822.86, 30100, 41567.13, 25400, 23125, 40073.75, 16505.82, 17770, 38406.03, 1528.25, 23475.77, 29869.69, 17020, 19270, 13085.47, 10607.48, 7800, 15220, 15260, 17580, 25094.66, 3908.74, 8150, 25055.89, 19690.65, 12445.4, 10347.39, 7645.39, 49300, 8690, 13660, 16510, 34457.08, 522.68, 10202, 18900, 25027.1, 24956.42, 23259, 32743, 37226, 32697, 32258, 31336.67, 36135.81, 4389.26, 12450, 46220.43, 36770.7), year = c("2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2015", "2015", "2015", "2015"), month = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04")), .Names = c("amount", "year", "month"), class = c("tbl_df", "data.frame"), row.names = c(NA, -64L))