[R] Help with if statements

Carl Witthoft carl at witthoft.com
Tue Jun 9 23:14:30 CEST 2009


<quote>
 > Error in if (ALLRESULTS[i, 16] <= 0.05) significance_count = 
significance_count + :
 > missing value where TRUE/FALSE needed
 >
 > The script is included below
 >
 > it works if i convert the NA values to zero but this is not 
appropriate as it includes the zero as significant.
 >
 > ANY SUGGESTIONS
significance.count <- rowSums(ALLRESULTS[,16:22] <= .05, na.rm=TRUE)

?rowSums
</quote>

Good solution.

I would like to comment on the OP's naivete:  since he knows that zero 
is a value of interest to his algorithm, why the heck replace "NA" with 
zero?  In general, if there is some reason not to use na.rm or na.omit, 
  start out by thinking about what NA values mean to your analysis.  If 
they are the equivalent of "FALSE" conditions, then replace them with a 
numerical value which is "FALSE".  In this example,  replacing NA with 
0.051 would do just fine.




More information about the R-help mailing list