replaceNA: Replace NA in categorical data

Description Usage Arguments Value Author(s) Examples

Description

This functions replaces NA by the string subst. The function can easily be used within lapply strutctures.

Usage

1
  replaceNA(x, subst)

Arguments

x

vector that possibly contains NAs

subst

character string that contains substitution of NA.

Value

factor that contains a level denoted by 'subst' instead of NAs.

Author(s)

Matthias Bannert

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# some vector that contains NAs
someVector <- c(1,2,NA,NA,3,1,2,2,0,9,4,NA,9,2)

# replace all NAs by string and turn 
# variable into factor
replaceNA(someVector,"empty")

# turning NA into a category is common use case
table(someVector)
table(someVector,useNA="alw")
table(replaceNA(someVector,"empty"))

mbannert/gateveys documentation built on May 21, 2019, 2:23 p.m.