Extracts the completed data from a
Takes an object of class
mids, fills in the missing data, and returns
the completed data in a specified format.
An object of class
midsas created by the function
A numeric vector or a keyword. Numeric values between 1 and
data$mreturn the data with imputation number
actionfilled in. The value of
action = 0return the original data, with missing values.
actioncan also be one of the following keywords:
"repeated". See the Details section for the interpretation. The default is
action = 1Lreturns the first imputed data set.
A logical to indicate whether the original data with the missing values should be included.
A logical indicating whether the return value should always be an object of class
mild = TRUEoverrides
"repeated". The default is
Additional arguments. Not used.
Complete data set with missing values replaced by imputations.
data.frame, or a list of data frames of class
action can be length-1 character, which is
matched to one of the following keywords:
mildobject of imputed data sets. When
include = TRUE, then the original data are appended as the first list element;
produces a data set where imputed data sets are stacked vertically. The columns are added: 1)
.imp, integer, referring the imputation number, and 2)
.id, character, the row names of
"long"but without the two additional columns;
produces a data set with where imputed data sets are stacked horizontally. Columns are ordered as in the original data. The imputation number is appended to each column name;
"broad", but with columns in a different order.
mice 3.7.5 renamed the
complete.mids() and exported it as an S3 method of the
tidyr::complete(). Name clashes between
tidyr::complete() should no
# obtain first imputed data set sum(is.na(nhanes2)) #>  27 imp <- mice(nhanes2, print = FALSE, maxit = 1) dat <- complete(imp) sum(is.na(dat)) #>  0 # obtain stacked third and fifth imputation dat <- complete(imp, c(3, 5)) # obtain all datasets, with additional identifiers head(complete(imp, "long")) #> .imp .id age bmi hyp chl #> 1 1 1 20-39 22.7 no 113 #> 2 1 2 40-59 22.7 no 187 #> 3 1 3 20-39 33.2 no 187 #> 4 1 4 60-99 22.0 no 238 #> 5 1 5 20-39 20.4 no 113 #> 6 1 6 60-99 22.5 no 184 # same, but now as list, mild object dslist <- complete(imp, "all") length(dslist) #>  5 # same, but also include the original data dslist <- complete(imp, "all", include = TRUE) length(dslist) #>  6 # select original + 3 + 5, store as mild dslist <- complete(imp, c(0, 3, 5), mild = TRUE) names(dslist) #>  "0" "3" "5"