I have a dataframe which looks like the following:
library(tidyverse)
full.df<-tibble(x = c(1.5, 2.5, 3.5, 5.6, 7.4),
y = c(4.5, 4.3, 2.6, 5.6, 7.6),
a = c(1, 2, 3, 4, 5),
b = c(5, 6, 7, 8, 9))
And a second dataframe that's essentially a subset of full.df
but missing columns a
& b
:
subset.df<-tibble(x = c(1.5, 3.5, 7.4),
y = c(4.5, 2.6, 7.6))
How can I filter full.df
on x
& y
using x
& y
from subset.df
? I wish to return this:
# A tibble: 3 x 4
x y a b
<dbl> <dbl> <dbl> <dbl>
1 1.5 4.5 1 5
2 3.5 2.6 3 7
3 7.4 7.6 5 9
I have tried full.df %>% filter(x == subset.df$x & y == subset.df$y)
but this only returns the first row.