I have an empty tibble full of NA's with the rows and columns, respectively named for id numbers and all the dates in a period of time. For example, this code:
tbl <- tibble(PERSONAL_ID = c("A", "B", "C", "D"))
dates = as.character((seq(as.Date("2016-01-01"), as.Date("2016-01-05"), by="days")))
tbl[dates] <- NA
tbl <- column_to_rownames(tbl, var = "PERSONAL_ID")
I have a second tibble that contains columns matching up one ID number with one date, as in this example:
enrollments <- tibble(ID = c("D", "B", "C", "D"),
date = c("2016-01-01", "2016-01-03", "2016-01-05", "2016-01-02"))
What I would like to do is add "1" to the row and column of the first tibble (tbl) corresponding to the ID and date listed in the second tibble (enrollments). For the example code above, the desired output would be:
2016-01-01 2016-01-02 2016-01-03 2016-01-04 2016-01-05
A <NA> <NA> <NA> <NA> <NA>
B <NA> <NA> 1 <NA> <NA>
C <NA> <NA> <NA> <NA> 1
D 1 1 <NA> <NA> <NA>
Thank you!