使用dplyr筛选包含特定字符串的行

我必须使用包含字符串的那些行作为标准来过滤数据帧RTB。我正在使用dplyr。


d.del <- df %.%

  group_by(TrackingPixel) %.%

  summarise(MonthDelivery = as.integer(sum(Revenue))) %.%

  arrange(desc(MonthDelivery))

我知道我可以在其中使用该函数filter,dplyr但是我不完全知道如何告诉它检查字符串的内容。


我尤其要检查列中的内容TrackingPixel。如果字符串包含标签,RTB我想从结果中删除该行。


冉冉说
浏览 7600回答 3
3回答

倚天杖

这个答案与其他答案相似,但是使用preferred stringr::str_detect和dplyr rownames_to_column。library(tidyverse)mtcars %>%&nbsp;&nbsp; rownames_to_column("type") %>%&nbsp;&nbsp; filter(stringr::str_detect(type, 'Toyota|Mazda') )#>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type&nbsp; mpg cyl&nbsp; disp&nbsp; hp drat&nbsp; &nbsp; wt&nbsp; qsec vs am gear carb#> 1&nbsp; &nbsp; &nbsp; Mazda RX4 21.0&nbsp; &nbsp;6 160.0 110 3.90 2.620 16.46&nbsp; 0&nbsp; 1&nbsp; &nbsp; 4&nbsp; &nbsp; 4#> 2&nbsp; Mazda RX4 Wag 21.0&nbsp; &nbsp;6 160.0 110 3.90 2.875 17.02&nbsp; 0&nbsp; 1&nbsp; &nbsp; 4&nbsp; &nbsp; 4#> 3 Toyota Corolla 33.9&nbsp; &nbsp;4&nbsp; 71.1&nbsp; 65 4.22 1.835 19.90&nbsp; 1&nbsp; 1&nbsp; &nbsp; 4&nbsp; &nbsp; 1#> 4&nbsp; Toyota Corona 21.5&nbsp; &nbsp;4 120.1&nbsp; 97 3.70 2.465 20.01&nbsp; 1&nbsp; 0&nbsp; &nbsp; 3&nbsp; &nbsp; 1由reprex软件包(v0.2.0)于2018-06-26创建。
打开App,查看更多内容
随时随地看视频慕课网APP