title: where to put na.rm=T in my apply function
body: <p>I have three populations for which I am calculating allele frequency using the following code. I have made a matrix to store the allele frequencies</p>
  
  <pre><code>M=matrix(NA,nrow(mydata),3,) #3 populations
  colnames(M)=c("pop1","pop2","pop3")
  </code></pre>
  
  <p>and then calculate for each population using</p>
  
  <pre><code>#population 1
  M[,1]=(apply(mydata[,which(colnames(mydata)=="pop1")],
  1,function(x) sum(x)/(length(x)*2))
  </code></pre>
  
  <p>Where would I put na.rm=T so that I don't get an error due to the NAs in my data? I have tried</p>
  
  <pre><code>M[,1]=(apply(mydata,na.rm=T[,which(colnames(mydata)=="pop1")],
  1,function(x) sum(x)/(length(x)*2))
  </code></pre>
  
  <p>but I get an error back (incorrect number of dimensions)</p>