0

I have a data panel from 2009 to 2018 where each year (ano) there is an occurrence of the total number of employees (total) for each company (cnpjcei).

   ano    cnpjcei       total
   <dbl> <chr>         <int>
 1  2009 1000786001505    25
 2  2010 1000786001505    23
 3  2011 1000786001505    10
 4  2012 1000786001505     8
 5  2013 1000786001505     7
 6  2014 1000786001505     9
 7  2015 1000786001505     9
 8  2016 1000786001505     9
 9  2017 1000786001505     8
10  2018 1000786001505     9
11  2009 1001193000168    32
12  2010 1001193000168    41
13  2011 1001193000168    76
14  2012 1001193000168    93
15  2013 1001193000168    67
16  2014 1001193000168    75
17  2015 1001193000168    42
18  2016 1001193000168    91
19  2017 1001193000168    68
20  2018 1001193000168    84

Basically, I want to calculate the average number of employees in the period (2009 to 2018) for each company (cnpjcei)


  cnpjcei        average
   <chr>          <int>
 1  1000786001505 11.7
 2  1001193000168 66.9

Suggestions?

  • If you are looking for a tidyverse approach search for `group_by` and `summarise`, maybe this link will help: https://stackoverflow.com/questions/44168756/compute-average-of-grouped-data-frame-using-dplyr-and-tidyr – Peter Dec 02 '21 at 22:37

0 Answers0