mardi 6 décembre 2016

why this ifelse statement in R doesn't give expected results

i intend to mark everything between -1 and 2 as 1 and all else 0

df=data.frame(a=c(1,-1,0,2,5))
df$b=ifelse(df$a<=2&&df$a>=-1,1,0)

however, the result shows all 1 in b column. What went wrong here?

Aucun commentaire:

Enregistrer un commentaire