-1

Below is the image that describes my data frame, I wish to conditionally delete all city names which have "Range" written in them as indicated in the snippet. I tried various approaches but haven't been successful so far. enter image description here

pogibas
  • 27,303
  • 19
  • 84
  • 117
  • Some code to generate data would be much more useful than a screenshot, it would help others help you. See http://reprex.tidyverse.org for how to make a reprex. – Romain Francois Sep 23 '17 at 18:37

2 Answers2

3

There are two things: detect a pattern in a character vector, you can use stringr::str_detect() and extract a subset of rows, this is dplyr::filter() purpose.

library(dplyr)
library(stringr)
df <- df %>%
  filter( ! str_detect(City, "Range") )
Romain Francois
  • 17,432
  • 3
  • 51
  • 77
1

Use grep with invert option to select all lines without Range.

yourDataFrame <- yourDataFrame[grep("Range", yourDataFrame$City, invert = TRUE), ]
pogibas
  • 27,303
  • 19
  • 84
  • 117