I've been using R for data manipulating for quite a long time, and recently I found the conditional statement in R is not right based on my data results. Here is an example of my data set:
tail(ncmi[which(ncmi$type=='Above'),])
p freq freq.pred pred.lwr pred.upr type
OTU328 0.0008791327 1 1 0.7224672 1 Above
OTU81 0.0008872229 1 1 0.7224672 1 Above
OTU2322 0.0008953131 1 1 0.7224672 1 Above
OTU55 0.0009087967 1 1 0.7224672 1 Above
OTU6952 0.0009141902 1 1 0.7224672 1 Above
OTU5350 0.0009249771 1 1 0.7224672 1 Above
If the number in freq is bigger than that of pred.upr, then the type is set as 'Above', as you can see, none of these results in freq is bigger than pred.upr, while the data type is set as 'Above'.
The conditional statement in my code is as below:
ncmi$type <- ''
for (k in 1:nrow(ncmi)) {
if(ncmi$freq[k]>ncmi$pred.upr[k]){
ncmi$type[k] <- 'Above'
}else if(ncmi$freq[k]<ncmi$pred.lwr[k]){
ncmi$type[k] <- 'Below'
}else{
ncmi$type[k] <- 'Neutral'
}
}
Why would this happen?