My question seems simple and a lot of similar things have been asked already, but i haven't found something combing questions like this one and this one, where i do want to fill existing variables based on their column names and! an other variable. I posted some test code to showcase the problem:
require(tibble)
set.seed(123)
dat1 <- as.tibble(data.frame("ID"=rep(1:10,3), "Stuff"=rep(c("A","B","C"),10),"Target"=runif(30)))
dat2 <- as.tibble(data.frame("ID"=1:10, "A"=rep(NA,10), "B"=rep(NA,10), "C"=rep(NA,10) ) )
I would like to fill the columns in dat2 with the values in "Target" based on "ID" and "Stuff" from dat1. I think it has to some combination of the to linked problems.
(My regular dataset does include about 20 columns to be filled in and about 20'000 datapoints in dat1.)