filter with characters

Hi. Why does the second filter fail, when the first filter succeeds?

suppressMessages(library(dplyr))
x <- c(5,1,3,2,5)
y <- c(1,5,3,4,2)
data <- data.frame(x,y)
data
result <- data %>%
filter(x=="5" | y=="4")
result

x <- c("a","b","c","d","a")
y <- c("f","g","a","e",K")
data <- data.frame(x,y)
data
result <- data %>%
filter(x == "a" | y = "e")
result

Error: unexpected string constant in:
"result <- data %>%
filter(x == ""
Execution halted

y <- c("f","g","a","e",K")

the K is not fully wrapped in quotes, if you use Rstudio this should have been strongly visually hinted by the colour scheme ?

filter(x == "a" | y = "e")

y= should be y==

1 Like

Whoops, of course.

By the way, I have color issues :slight_smile:

Thank you.

This topic was automatically closed 7 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.