How can I create a new column in R with aggregated values from another column

215 views Asked by At

I would like to create a column with aggregated voriginal.pngalues from the column country

To an aggregated/classified column of subregions. For example,ideal.png

1

There are 1 answers

0
scott.pilgrim.vs.r On

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