title: Using apply to find max in a data frame with missing values and strings
body: <p>I have the following data set:</p>
  
  <pre><code>df&lt;-data.frame(read.table(header = TRUE, text = "
       ID N1 N2 N3 N4
        1 2 3 4 5
       11 NA -12 14 55
       21 12 SON 34 14"))
  </code></pre>
  
  <p>I want to find out what is the max entry in each row. This would be, for example, 5 in the first row. Obviously, the situation is more complicated because of missing values ('NA') and a string ('SON').</p>
  
  <p>I first tried the following command:</p>
  
  <pre><code>df$Result&lt;-apply(df,1, max, na.rm= TRUE)
  </code></pre>
  
  <p>The results are [5,55, SON]! Not what I wanted. I therefore then tried:</p>
  
  <pre><code>checkd&lt;- function(x) if(is.integer(x)== TRUE)max(x)
  df$Result&lt;-apply(df,1, checkd)
  </code></pre>
  
  <p>Funnily, it removed the last column <code>df$Result</code>. Does anyone know what did I do wrong? Also, what would be the solution to my problem?</p>
  
  <p>Also, of I try the following code:</p>
  
  <pre><code>checkd&lt;- function(x) if(is.integer(x)== TRUE)max(x)
  df$Result&lt;-apply(df,1, checkd, na.rm= TRUE)
  </code></pre>
  
  <p>it gives me <code>Error in FUN(newX[, i], ...) : unused argument (na.rm = TRUE)</code>! Why is that? My function <code>checkd</code> does generally not seem to cause any problems to R. Why does R reject <code>na.rm= TRUE</code> when I use <code>checkd</code> but not when I use <code>max</code> in apply?</p>
  
  <p>Thanks,</p>
  
  <p>Dom</p>