title: Average per group
body: <p>I have a repetitive task of calculating the average price of a product for each country. Price and country code (e.g., ES = Spain , TR = Turkey) are located in two different columns in my dataframe. How can I use a for-loop to iterate over the different countries?</p>
  
  <pre><code># get price for ES only
  ES = subset(training.data.raw$priceusd, training.data.raw$destinationcountry== "ES")
  # sum all prices of ES
  summyES = sum(ES)
  # Freq of ES
  FES = 5223
  # avg price of ES
  (avgES = summy/FES)
  
  # AVG price for TR
  TR = subset(training.data.raw$priceusd, training.data.raw$destinationcountry=="TR")
  summyTR = sum(TR)
  FTR = 3201
  avgTR = summy/FTR
  print(avgTR)
  </code></pre>