I would like to copy the value from a dataframe to another dataframe. The difficulty for me is that I have four groups in both dataframes and in the dataframe where I would like to copy the values, I have several columns where I want to insert the value. More specifically, the dataframe (df1) from which I would like to copy the values looks like this:
structure(list(Name = c("A", "B", "C", "D"), Value = c(2L, 5L,
3L, 2L)), class = "data.frame", row.names = c(NA, -4L))
The dataframe (df2) where I want to insert the values looks like this:
structure(list(Name = c("A", "B", "C", "D"), `Rating 2017-06` = c(NA,
NA, NA, NA), `Rating 2017-07` = c(NA, NA, NA, NA), `Ratin g 2017-08` = c(NA,
NA, NA, NA), `Rating 2017-09` = c(NA, NA, NA, NA), `Rating 2017-10` = c(NA,
NA, NA, NA), `Rating 2017-11` = c(NA, NA, NA, NA), `Rating 2017-12` = c(NA,
NA, NA, NA), `Rating 2018-01` = c(4L, 4L, 3L, 3L), `Rating 2018-02` = c(3L,
4L, 3L, 2L)), class = "data.frame", row.names = c(NA, -4L))
I would like to copy the data in df1 in column "Value" to df2 to columns 2 to 8 ("Rating 2017-06" to "Rating 2017-12") for each Name.
What I have tried so far:
Merged_Data <- df1 %>%
left_join(df1, df2, by="Name")
The problem is with this code that I cannot specifically copy the values form df1 to selected columns as mentioned above in df2. I don't know what I have to right in the code that I would be able to do that.
Could someone help me here? Thank you already.