Replacing value of a tibble from another tibble while matching index value or row value

Hello everyone,
I need to replace some value of a tibble based on another tibble while the index number or row value is matching. Lets see the problems below.

tibble1 <- tibble(a = c(1,2,3,4), b = c(0,0,0,0))
tibble2 <- tibble(a = c(2,4), b = c(53,98))

Here are two tibbles. The resultant of the operation should look like below.

# A tibble: 4 × 2
      a     b
  <dbl> <dbl>
1     1     0
2     2    53
3     3     0
4     4    98

But the condition is the problem should be solved without using any loop. Is there any other ways or any base R built-in functions to solve the issue.

Thanks in advance.

dplyr::rows_update(x=tibble1,
                   y=tibble2,
                   by="a")

Thank you @nirgrahamuk for your reply. If the column name is not same, is it possible to do the same operation ?

inline you can use the standard dplyr tools like rename() to rename the contributing column to match the column it should inform.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.