lolibility lolibility - 1 year ago 82
R Question

R how to change one of the level to NA

I have a data set and one of its column has factor levels

"a" "b" "c" "NotPerformed"
. How can I change all the
factors to NA?

Answer Source

Set the level to NA:

x <- factor(c("a", "b", "c", "NotPerformed"))
## [1] a            b            c            NotPerformed
## Levels: a b c NotPerformed
levels(x)[levels(x)=='NotPerformed'] <- NA
## [1] a    b    c    <NA>
## Levels: a b c

Note that the factor level is removed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download