title: Issue with Subset when doing a function
body: <p>I am trying to define a function, which would allow me to standardize the variable. I would like to standardize each observation with respect to its particular sub-industry. The output gives me NA...</p>
  <p>the code is the following:</p>
  <pre><code>standard&lt;-function(x){
  
    return((x - mean(subset(dat1,Industry==&quot;x&quot;),na.rm=TRUE)))
            
  }
  
  std_data&lt;-as.data.frame(apply(dat1[2:8],2,standard))
  </code></pre>