na.rm for other values in R
<p>I have a data frame</p>

<pre><code>df=data.frame(a=1:5,b=c(1,3,4,-999999,4))
</code></pre>

<p>and want to calculate the average of it, but want to exlcude the outlier, -9999 in this case</p>

<p>Is there a command similar to </p>

<pre><code>na.rm
</code></pre>

<p>so I can go</p>

<pre><code>apply(df,1,function(x) mean(if x&gt;-100 &amp; x &lt;100))
</code></pre>

<p>note that my df if 600 x 50 dim</p>