I would like to create a column with aggregated values from the column country
To an aggregated/classified column of subregions. For example,
I would like to create a column with aggregated values from the column country
To an aggregated/classified column of subregions. For example,
To aggregate in R:
agg_df <- aggregate(df$YVAR, by=list(df$XVAR), FXN)
Where df is your data frame. YVAR is your response variable, XVAR is your independent variables, such as sub region, and FXN is what you want aggregate()
to do with your YVAR, such as mean
or sum
or length
.
Here is the doc for more reading.
https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/aggregate