Skip to content

error in IF condition with factor evaluation

4 messages · Edoardo Baldoni, Eik Vettorazzi, Rui Barradas +1 more

#
Hi Edoardo,
there is a difference between comparisons and assignments, both
semantically as well as in R syntax: "==" vs "=" or "<-", latter being
more obvious an assignment.
This is the source of your error.
But to change the labels of a factor object, it is easier to do sth like

at<-factor(1:5,labels=letters[1:5])
at
levels(at)[3]<-"xyz"
at   #check

hth



Am 23.11.2012 10:42, schrieb edoardo baldoni:

  
    
#
Hello,

Try

if (!is.na(x[i]) && x[i] == "DISCONECTED")


Hope this helps,

Rui Barradas
Em 23-11-2012 09:42, edoardo baldoni escreveu:
#
Hi
If
dataset$STATUS.x

is factor, you can use

levels(dataset$STATUS.x)[2] <-"DISCONNECTED"

to rename second level (which appears to be DISCONECTED)

Regaards

Petr