Create a column which is an average of other columns

Hello,
I would try to create a new variable, which is the average of some of the other variables. I am working with countries and their GDPs (per month) and it asked me to make the average of them. Would someone here be able to help me in this ?
Thanks

Hi, what does your dataset look like? Can you provide a reproducible example? It would make it much easier to help.

I created some sample data:

df <- data.frame(cbind(
         January = c(100, 200, 300),
         February = c(110, 205, 307),
         March = c(117, 211, 315)))
rownames(df) = c("Albania", "Bahamas", "Chile")
df$average <- round(rowMeans(df),1)

df

        January February March average
Albania     100      110   117   109.0
Bahamas     200      205   211   205.3
Chile       300      307   315   307.3
2 Likes

Hello,
I'm sure you shared this image with the best intentions, but perhaps you didnt realise what it implies.
If someone wished to use example data to test code against, they would type it out from your screenshot...

This is very unlikely to happen, and so it reduces the likelihood you will receive the help you desire.
Therefore please see this guide on how to reprex data. Key to this is use of either datapasta, or dput() to share your data as code

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.