1
I have a database with data of Brazilian cities and states, I would like to filter only the states, all follow a pattern of having a "br_states_" before the name of the state. I tried to use the package string
and the function filter
package dplyr
, but to no avail.
Code I am using:
library(readr)
library(dplyr)
library(stringr)
dados <- read_csv('http://tiny.cc/idb-traffic-daily') %>%
filter(country_name == "Brazil") %>%
str_detect(pattern = "br_states_")
What was missing from your code were two things.1) the
str_detect
must be inside thefilter
. 2) You need to inform for thestr_detect
where he should seek the pattern, i.e., provide the first argument. Something like this:filter(..., str_detect(region_slug, "br_states_"))
– Tomás Barcellos