[R] Help with if statements
Amit Patel
amitrhelp at yahoo.co.uk
Tue Jun 9 18:17:30 CEST 2009
Hi
I am trying to create a column in a data frame which gives a sigificane score from 0-7. It should read values from 7 different colums and add 1 to the counter if the value is <=0.05. I get an error message saying
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
#SCRIPT STARTS
for (i in 1:length(ALLRESULTS[,1])) {
significance_count = 0
if (ALLRESULTS[i,16] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
if (ALLRESULTS[i,17] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
if (ALLRESULTS[i,18] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
if (ALLRESULTS[i,19] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
if (ALLRESULTS[i,20] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
if (ALLRESULTS[i,21] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
if (ALLRESULTS[i,22] <= 0.05 ) significance_count = significance_count +1 else significance_count = significance_count
ALLRESULTS[i,23] <- significance_count}
More information about the R-help
mailing list