Replace a subset of a data frame with dplyr join operations

前端 未结 4 485
栀梦
栀梦 2020-12-16 14:05

Suppose that I gave a treatment to some column values of a data frame like this:

  id animal weight   height ...
  1    dog     23.0
  2    cat     NA
  3           


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 14:46

    Isn't dplyr::rows_update exactly what we need here? The following code should work:

    df %>% dplyr::rows_update(sub_df, by = "id")
    

    This should work as long as there is a unique identifier (one or multiple variables) for your datasets.

提交回复
热议问题