I think this would just be a left_join in dplyr. It isn't apparent from the example data how the first table is ordered so I've assumed it has been set by something else:
t1 <- tibble::tribble(
~X, ~Y,
"X2", 12,
"X3", 8.2,
"X1", 1
)
t2 <- tibble::tribble(
~X, ~Y,
"X1", 1.0,
"X3", 8.2,
"X2", 4.3
)
The following code joins the tables and drops the Y column from the first table as it's not included in the select(). Also note that the columns become Y.x and Y.y in the join because they are the same name. I've renamed it back to Y but this might not be an issue in your real data:
library(dplyr)
new_output <- t1 %>%
left_join(t2, by = "X") %>%
select(X,
Y = Y.y)
Output:
# A tibble: 3 x 2
X Y
<chr> <dbl>
1 X2 4.3
2 X3 8.2
3 X1 1