I am trying to calculate average age of each US county weighted by the population of each age group in my data.
My data set looks like this:
state county age population
AL Autauga 1 2366
AL Autauga 2 3029
AL Autauga 3 3619
AL Autauga 4 3043
AL Autauga 5 3776
I'm trying to run something like this:
agedata <- aggregate(data$age, list(data$state, data$county), weighted.mean(data$age, data$population))
Whenever I run this command I get the following error:
Error in match.fun(FUN) : 'weighted.mean(fulldata$age, fulldata$population)' is not a function, character or symbol