-1

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
    Please [don’t post your data as an image](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors). Instead, run `dput(dataname)` in R, replacing “dataname” with the name of your dataframe. Then [edit] your post and copy and paste the `dput()` result from R. – zephryl Nov 12 '22 at 15:23
  • Also, where are you getting the subregion values from? Do you have a separate vector or dataframe that links countries to subregions? – zephryl Nov 12 '22 at 15:25
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems. One way of doing this is by using the `dput` function. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Nov 15 '22 at 03:03

1 Answers1

0

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