0

I am trying to see the change in variable "A004" on country level, year on year. The data I have is on individual level. Sample Data:

cntry_AN year A004
AL 2010 3
AL 2010 4
AL 2011 2
AL 2012 3
DZ 2010 3
DZ 2011 2
DZ 2011 3

I want the output to look like(replaced with means):

cntry_AN 2010 2011 2012
AL 3.5 2 3
DZ 3 2.5 -

Here's the code I am trying:

country_year_summary <- file1 %>% 
  group_by(cntry_AN,year) %>% 
  select(A004) %>% 
  dplyr::summarize(averaged.M = mean(A004))

0 Answers0