I'm trying to average several time period of a particular variable column in a unit-time dataframe into a new datafame that is just unit and average of each time periods. I'm not quite sure how to do this, can anyone help?
Base data:
A <- structure(list(country = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "USA", class = "factor"),
year = c(2000, 2001, 2002, 2003, 2004, 2005), var1 = c(2,
5, 4, 6, 7, 8)), class = "data.frame", row.names = c(NA, -6L))
Desired output
B <- structure(list(country1 = structure(1L, .Label = "USA", class = "factor"),
var1.2000.2002 = 3.667, var1.2003.2005 = 7), class = "data.frame", row.names = c(NA, -1L))