matchcases | R Documentation |
Find one or more cases from a pool
data.frame that match cases in a target
data.frame. Match exactly and/or by distance (sum of squared distances).
matchcases(
target,
pool,
n.matches = 1,
target.id = NULL,
pool.id = NULL,
exactmatch.factors = TRUE,
exactmatch.cols = NULL,
distmatch.cols = NULL,
norepeats = TRUE,
ignore.na = FALSE,
verbose = TRUE
)
target |
data.frame you are matching against |
pool |
data.frame you are looking for matches from |
n.matches |
Integer: Number of matches to return |
target.id |
Character: Column name in |
pool.id |
Character: Same as |
exactmatch.factors |
Logical: If TRUE, selected cases will have to
exactly match factors
available in |
exactmatch.cols |
Character: Names of columns that should be matched exactly |
distmatch.cols |
Character: Names of columns that should be distance-matched |
norepeats |
Logical: If TRUE, cases in |
ignore.na |
Logical: If TRUE, ignore NA values during exact matching. |
verbose |
Logical: If TRUE, print messages to console. Default = TRUE |
E.D. Gennatas
set.seed(2021)
cases <- data.frame(
PID = paste0("PID", seq(4)),
Sex = factor(c(1, 1, 0, 0)),
Handedness = factor(c(1, 1, 0, 1)),
Age = c(21, 27, 39, 24),
Var = c(.7, .8, .9, .6),
Varx = rnorm(4)
)
controls <- data.frame(
CID = paste0("CID", seq(50)),
Sex = factor(sample(c(0, 1), 50, TRUE)),
Handedness = factor(sample(c(0, 1), 50, TRUE, c(.1, .9))),
Age = sample(16:42, 50, TRUE),
Var = rnorm(50),
Vary = rnorm(50)
)
mc <- matchcases(cases, controls, 2, "PID", "CID")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.