如何在 R 中更新数据集

How to update dataset in R

Df1:

ID   Score   Test
1     97        1
1     98        2 
2     85        1
2     NA        2
3     NA        1
3     79        2

Df2:

ID   Score      Test
2    70           2
3    60           1

想要的结果:

ID   Score   Test
1     97        1
1     98        2 
2     85        1
2     70        2
3     60        1
3     79        2

我实际上有一个更大的数据框和总共 5 个测试。我想使用 DF2 中的分数更新 DF1 中的 NA 分数。 我如何在 R 中执行此操作?

这个有用吗:

library(dplyr)
df %>% left_join(df1, by = c('ID','Test')) %>% 
   mutate(Score = coalesce(Score.x, Score.y)) %>% 
   select(-2,-4) %>% relocate(1,3,2)
# A tibble: 6 x 3
     ID Score  Test
  <dbl> <dbl> <dbl>
1     1    97     1
2     1    98     2
3     2    85     1
4     2    70     2
5     3    60     1
6     3    79     2