[R] Problems with na.rm=T

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Jun 14 17:13:19 CEST 2007


Lucke, Joseph F wrote:
> Suddenly (e.g. yesterday) all my functions that have "na.rm=" as a
> parameter (e.g., mean(), sd(), range(), etc.) have been reporting
> warnings with "na.rm=T". The message is "Warning message: the condition
> has length > 1 and only the first element will be used in: if (na.rm) x
> <- x[!is.na(x)] ".   This has never happened before.  I don't recall
> having done anything that might generate this message.  How do I fix

  Do you have something called 'T':

 > T=c(1,2,3,4)
 > mean(x,na.rm=T)
[1] 2
Warning message:
the condition has length > 1 and only the first element will be used in: 
if (na.rm) x <- x[!is.na(x)]

  You should always use 'TRUE' for true and 'FALSE' for false. R makes 
it harder to shoot yourself in the foot that way:

 > TRUE=c(1,2,3)
Error in TRUE = c(1, 2, 3) : invalid (do_set) left-hand side to assignment

help(TRUE) helps:

Details:

      'TRUE' and 'FALSE' are part of the R language, where 'T' and 'F'
      are global variables set to these. All four are 'logical(1)'
      vectors.

Barry



More information about the R-help mailing list