if statement - how to fix error "missing value where TRUE/FALSE needed" at R? -


my code :

for(k in 1:length(dat)){    if(dat==boxplot(dat)$out[k]){       dat<-na    } } 

and result

error in if (dat == boxplot(dat)$out[k]) { :    missing value true/false needed 

how fix it?

could 1 of 2 things; fix specific error

for(k in 1:length(dat)){         if(length(boxplot(dat)$out ) & dat==boxplot(dat)$out[k]){           dat<-na         }       } 

but that's clunky r code. better might be:

dat[ dat %in% boxplot(dat)$out ] <- na 

(it is, however, statistical malpractice remove outliers.)


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -