impute | R Documentation |
These functions do simple and transcan
imputation and print, summarize, and subscript
variables that have NAs filled-in with imputed values. The simple
imputation method involves filling in NAs with constants,
with a specified single-valued function of the non-NAs, or from
a sample (with replacement) from the non-NA values (this is useful
in multiple imputation).
More complex imputations can be done
with the transcan
function, which also works with the generic methods
shown here, i.e., impute
can take a transcan
object and use the
imputed values created by transcan
(with imputed=TRUE
) to fill-in NAs.
The print
method places * after variable values that were imputed.
The summary
method summarizes all imputed values and then uses
the next summary
method available for the variable.
The subscript method preserves attributes of the variable and subsets
the list of imputed values corresponding with how the variable was
subsetted. The is.imputed
function is for checking if observations
are imputed.
impute(x, ...)
## Default S3 method:
impute(x, fun=median, ...)
## S3 method for class 'impute'
print(x, ...)
## S3 method for class 'impute'
summary(object, ...)
is.imputed(x)
x |
a vector or an object created by |
fun |
the name of a function to use in computing the (single)
imputed value from the non-NAs. The default is |
object |
an object of class |
... |
ignored |
a vector with class "impute"
placed in front of existing classes.
For is.imputed
, a vector of logical values is returned (all
TRUE
if object
is not of class impute
).
Frank Harrell
Department of Biostatistics
Vanderbilt University
fh@fharrell.com
transcan
, impute.transcan
, describe
, na.include
, sample
age <- c(1,2,NA,4)
age.i <- impute(age)
# Could have used impute(age,2.5), impute(age,mean), impute(age,"random")
age.i
summary(age.i)
is.imputed(age.i)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.