In order to replace the NAs in a factor an additional level has to be defined first. This function does this and replaces the NAs by the given level.

NALevel(x, level)

Arguments

x

a vector which will be turned into a factor.

level

the name for the new level

Value

the vector x with the NAs replaced by level

Author

Andri Signorell <andri@signorell.net>

See also

Examples

x <- c(LETTERS[1:5], NA)
table(NALevel(x, "something else"))
#> 
#>              A              B              C              D              E 
#>              1              1              1              1              1 
#> something else 
#>              1