I'm kind of new to this so I will try to make it as clear as possible.
I have a data frame composed of 5 vectors. The first one contains country names and the other 5 are values that came from a survey. Each row represents the answers given by someone to said survey.
Country V1 V2 V3 V4 V5
Canada 1 2 4 1 2
Canada 1 3 2 2 3
Switzerland 3 1 1 1 1
Switzerland 1 4 3 4 2
I want to create a code that aggregate the results of my survey questions and then calculate the mean for every country in my data frame so I end up with only one value per country.
vAggregateCan <- (V1 + V2 + V3 + V4 + V5)/5
canValue <- mean(vAggregateCan)
I want to end up with a new data frame that contains only one entry of each country present in my initial data frame associated with the value resulting from the code I show as an example. That should look like this.
Country Value
Canada canValue
Switzerland swissValue
Problem is, I don't know how to tell R to only aggregate the values for specific countries and I would like to find a way to do that operation as simply as possible without having to repeat the same operations over and over.
Like I said I'm kind of new with that and I'm not sure if my question is clear. Thanks for the help.