View source: R/checkUniqueness2.R
checkUniqueness2 | R Documentation |
Function to check if a variable is unique for all cases of an identifier variable. This is a fast and more efficient version of
checkUniqueness
which always returns a logical, non missing value of length one.
checkUniqueness2(GADSdat, varName, idVar, impVar)
GADSdat |
|
varName |
Single string containing the variable name for which the check should be performed. |
idVar |
Single string containing the name of the identifier variable. |
impVar |
Single string containing the name of the imputation number. |
For example if missing values are multiple imputed and data is stored in a long format, checking the uniqueness of a variable
within an identifier can be tricky. This function automates this task via reshaping the data into wide format and testing equality
among the reshaped variables. Similar functionality (via matrices) is covered by lme4::isNested
,
which is more general and performs similarly.
Returns a logical of length one.
## create an example GADSdat
l <- 1000
long_df <- data.table::data.table(id = sort(rep(1:l, 15)),
v1 = sort(rep(1:l, 15)),
imp = rep(1:15, l))
gads <- import_DF(long_df)
## check uniqueness
checkUniqueness2(gads, varName = "v1", idVar = "id", impVar = "imp")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.