I have a data frame with a list of identifiers (names_ex). I then have a list of identifiers matched with cohorts at a particular point in time (cohort_list). My goal is to see a time-series of the cohort each identifier belongs to.
In practice, I have a ncol(names_ex) = 2000 names and length(cohort_list) = 200.
This question is not a duplicate of: Simultaneously merge multiple data.frames in a list
The names_ex vector makes it quite different. Also in practice I have many more elements in cohort_list, and I can't manually combine them 1 by 1
names_ex <- as.data.frame(c("AB1", "AB2", "AB3", "AB4", "AB5", "AB6", "AB7", "AB8", "AB9", "AB10"))
match1 <- as.data.frame(rbind(c("AB1",1),
c("AB9",2),
c("AB8",3),
c("AB2",1)))
match2 <- as.data.frame(rbind(c("AB3",2),
c("AB4",4),
c("AB6",4),
c("AB7",3)))
match3 <- as.data.frame(rbind(c("AB9",1),
c("AB8",1),
c("AB2",1),
c("AB6",3),
c("AB10",1)))
colnames(match1) <- c("Name", "Cohort")
colnames(match2) <- c("Name", "Cohort")
colnames(match3) <- c("Name", "Cohort")
cohort_list <- list(match1,match2,match3)
output <- cbind.data.frame(c("AB1", "AB2", "AB3", "AB4", "AB5", "AB6", "AB7", "AB8", "AB9", "AB10"),
c(1, 1, NA, NA, NA, NA, NA, 3, 2, NA),
c(NA, NA, 2,4, NA, 4, 3, NA, NA, NA),
c(NA, 1, NA, NA, NA, 3, NA, 1, 1, 1))