Help with filter() error in dplyr

Hi everyone! I’m doing the Applied Epi R course and I’m having trouble with the filter() function from dplyr.

Here is my reprex:

library(dplyr)

data <- data.frame(
  age = c(20, 30, 40),
  district = c("Bolo", "Kulo", "Bolo")
)

data %>%
  filter(district = "Bolo")  # This gives an error

I expected this to return rows where district is Bolo, but I get an error.

Any help would be appreciated — thank you!

Kia ora Teo,

Pay special attention to the third line of the error:

Error in `filter()`:
! We detected a named input.
ℹ This usually means that you've used `=` instead of `==`.
ℹ Did you mean `district == "Bolo"`?

You want to use == instead of = when you are filtering. In formal language, = is for assigning values, while == evaluates equality.