-1

I would like to calculate the temperature mean for each country. I have a data.frame of 10 countries and their respective temperatues. As you see:

    Country amp_temperature
1   France  17,6
2   France  17,2
3   Italy   17,4
4   Slovenia    18,6
5   Slovenia    18,3
6   Estonia 23,8
7   Estonia 22,7
8   Estonia 21,5
9   Estonia 23,1
10  Estonia 23,7
11  Estonia 23,8
12  Estonia 22,9
13  Estonia 23,6
14  Norway  21,4

Thank you very much for your help!

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Rinot
  • 199
  • 2
  • 10

2 Answers2

2

Suppose your data is DF, aggregate function should be one good alternative.

> aggregate(amp_temperature~Country, FUN=mean, data=DF)
   Country amp_temperature
1  Estonia         23.1375
2   France         17.4000
3    Italy         17.4000
4   Norway         21.4000
5 Slovenia         18.4500

You can check this answer which gives several anternatives to do what you need.

Community
  • 1
  • 1
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
1
tapply(mydata$amp_temperature,mydata$Country,mean)
Metrics
  • 15,172
  • 7
  • 54
  • 83