library(dplyr)
Toy dataset:
df <- data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
df
x y
1 1 4
2 2 5
3 3 6
This works fine:
df %>% filter(y == 5)
x y
1 2 5
This also works fine:
z <- 5
df %>% filter(y == z)
x y
1 2 5
But this fails
y <- 5
df %>% filter(y == y)
x y
1 1 4
2 2 5
3 3 6
Apparently, dplyr cannot make the distinction between its column y
and the global variable y
.
Is there a way to tell dplyr that the second y is the global variable?