0

I have a Data frame 1 that runs from 1931 until 2020, I need to count how many records per year there are and create a table that only shows year and count. I'm trying to loop over a variable (in this case the year) but I'm just getting the table 2 with 1 row of the data of 2020.

    for(i in c("2011",
              "2012",
              "2013",
              "2014",
              "2015",
              "2016",
              "2017",
              "2018",
              "2019",
              "2020")){
  
  prueba <- prueba2 %>%
  filter(year == i) %>%
  group_by(year)%>%
  summarise(freq=n())}

1 Answers1

0

This will produce a count by year:

prueba %>% count(year)
jnorman
  • 606
  • 8
  • 14