0
londonofficemarch<-londonofficemarch %>% 
  filter(str_detect(BNF_CODE, "0501"))

is my code. However, this finds values in the BNF_CODE column that have 0501 anywhere in them. I want only terms that have 0501 at the beginning of them. Is there a capability in R to do this?

Landon
  • 93
  • 11
  • You can use `startsWith(BNF_CODE, "0501")`, possible dupe of https://stackoverflow.com/questions/31467732/does-r-have-function-startswith-or-endswith-like-python/38151842#38151842 – IceCreamToucan Jul 27 '21 at 14:37
  • Or, use the regex special character `^` which indicates the start of the string, so `str_detect(BNF_CODE, "^0501")` will also work – Gregor Thomas Jul 27 '21 at 14:43
  • You can also use `str_detect(BNF_CODE, "^0501")`. The `^` matches the pattern but only at the start of a string. (EDIT: Sorry didn't see the above answer) – Tob Jul 27 '21 at 14:44

0 Answers0