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
Post a Comment