I would like to create a new dataset called df3
that joins the two datasets and looks like this:
Output
date2 coef
01-01-2022 1
01-01-2022 2
03-01-2021 3
03-01-2021 2
01-02-2021 4
01-02-2021 5
That is, it is selected in the first column of df1
with the datbase df2
df1<- structure(
list(date2= c("01-01-2022","01-01-2022","03-01-2021","03-01-2021","01-02-2021","01-02-2021"),
Category= c("ABC","CDE","ABC","CDE","ABC","CDE"),
coef= c(5,4,0,2,4,5)),
class = "data.frame", row.names = c(NA, -6L))
date2 Category coef
1 01-01-2022 ABC 5
2 01-01-2022 CDE 4
3 03-01-2021 ABC 0
4 03-01-2021 CDE 2
5 01-02-2021 ABC 4
6 01-02-2021 CDE 5
df2<- structure(
list(coef= c(1,2,3,2,4,5)),
class = "data.frame", row.names = c(NA, -6L))
coef
1 1
2 2
3 3
4 2
5 4
6 5