I have two dataframes. The first consists of data from 10 individuals, while the second consists in 1000. Variables are the same between dataframes:
set.seed(2022)
SmallCohort <- data.frame("ID" = paste0("S00", sample(1000:9999, 10)),
"Sex" = sample(c("M", "F")),
"Age" = sample(20:30, 10, replace = TRUE),
"Smoke" = sample(c("Y","N")),
"Disease" = sample(c("Y","N")))
BigCohort <- data.frame("Subj" = paste0("B00", sample(1000:9999, 1000)),
"Sex" = sample(c("M", "F")),
"Age" = sample(20:30, 1000, replace = TRUE),
"Smoke" = sample(c("Y","N")),
"Disease" = sample(c("Y","N")))
My goal is to find paired individuals from the BigCohort. Basically, I need to choose 10 unique individuals from the BigCohort paired for Sex, Age, Smoke and Disease with the same number of individuals from the small cohort.
I'm not looking for propensity score matching.
I tried this:
library(dplyr)
Combined <- inner_join(SmallCohort, BigCohort)