My dataframe named Vietnamese_age is like this:
- Vietnamese_city: Hanoi Danang HCMcity ...
- Age_population_from 10_to_20: 10000 20000 15000 ...
- Age_population_from 20_to_30: 15000 25000 15000 ...
- Age_population_from 30_to_40: 14000 28000 14000 ...
- Age_population_from 40_to_50: 21000 26000 12000 ... and so on
There are too many of age period, so I'm going to make a function which has a string variable, so when i insert a certain string ("Age population from 10 - 20"), it will show the boxplot of this age group in certain city and the mean of whole country.
I have built the very first function:
Age_function <- function(x) { mean(Vietnamese_age$x) }
and tried:
x = "Age_population_from 10_to_20"
resulting in the following error:
Error in Age_function(Age_population_from 10_to_20) : object 'Age_population_from 10_to_20' not found
What should I do to solve this problem?