-
Notifications
You must be signed in to change notification settings - Fork 48
/
replace_nas_with_explicit.Rd
49 lines (45 loc) · 1.47 KB
/
replace_nas_with_explicit.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utilities.R
\name{replace_nas_with_explicit}
\alias{replace_nas_with_explicit}
\title{Create explicit factor level for missing values}
\usage{
replace_nas_with_explicit(
scores,
new_na_label = "Unknown",
create_factor = FALSE,
add_unknown_level = FALSE
)
}
\arguments{
\item{scores}{An array of values, ideally either factor or character.
Required}
\item{new_na_label}{The factor label assigned to the missing value.
Defaults to \code{Unknown}.}
\item{create_factor}{Converts \code{scores} into a factor, if it isn't one
already. Defaults to \code{FALSE}.}
\item{add_unknown_level}{Should a new factor level be created?
(Specify \code{TRUE} if it already exists.) Defaults to \code{FALSE}.}
}
\value{
An array of values, where the \code{NA} values are now a factor level,
with the label specified by the \code{new_na_label} value.
}
\description{
Missing values are converted to a factor level.
This explicit assignment can reduce the chances that missing values
are inadvertently ignored. It also allows the presence of a missing
to become a predictor in models.
}
\note{
The \code{create_factor} parameter is respected only if \code{scores} isn't already
a factor. Otherwise, levels without any values would be lost.
A \code{stop} error will be thrown if the operation fails to convert all the
\code{NA} values.
}
\examples{
library(REDCapR) # Load the package into the current R session.
}
\author{
Will Beasley
}