if statement - Warning message when using If(...) function in R -


i'm having problems if function in r.

first tried this:

test<-matrix(10,3,3) if(test[2,2]==10) {test[2,2]<-5} 

ok, it's doing want. so, try this:

if(hylo.measures[i,3]=="clc0006x") {hylo.measures[i,3]<-"clc0005x"} 

ops! got following message:

warning message: in `[<-.factor`(`*tmp*`, iseq, value = "clc0005x") : invalid factor level, na generated 

i couldn't figure out going on here!

what obvious step missing?

that third column factor variable; might want check code make sure want. anyway, can add level manually if you're sure it's want do. here's example of adding level on iris

r>iris$species[5] <- "hahah" warning message: in `[<-.factor`(`*tmp*`, 5, value = c(1l, 1l, 1l, 1l, na, 1l, 1l,  :   invalid factor level, na generated  r>levels(iris$species) <- c(levels(iris$species), "hahah") r>iris$species[5] <- "hahah" r>iris[5,]   sepal.length sepal.width petal.length petal.width species 5            5         3.6          1.4         0.2   hahah 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -