title: Handling Data in long format in R
body: <p>I created a data frame in longformat which has 5 variables( company name, key item, country of origin, year and value) What I want to do is create a table with the means of the values of one key item for each year. Here is what I managed so far: </p>
  
  <pre><code>for(i in dat$Year) {
    dat[dat$KeyItem == "Total Assets" &amp; dat$Year == i, ]
    FUN1 &lt;- mean(dat$Value, na.rm = TRUE)
  
  
  }
  </code></pre>
  
  <p>I have hardly any experience in R and I am sorry if this question is too easy.
  Thank you guys in advance for your help. </p>