title: Functions for dataframes R
body: <p>I am trying to build a function for a dataframe, but I get an error when I run it. </p>
  
  <p><strong>Problem: How should I "apply" the function to a dataframe so that it works? Any workarounds for the atomic vector issue?</strong></p>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>Error in x$country: $ operator is invalid for atomic vectors</p>
  </blockquote>
  
  <p>The function is:</p>
  
  <pre><code>occ_fction &lt;- function (x)
  {
      x &lt;- subset(x, x$country== "DE")
      nace &lt;- model.matrix(~ nace_code -1, data=x)
      x &lt;- cbind(x, nace)
      rm(nace)
      # some more stuff here
  }
  </code></pre>
  
  <p>This is how I apply the function:</p>
  
  <pre><code>mapply(occ_fction, mydata)
  </code></pre>