为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

冉冉说 2019-10-14 11:19:12
我必须使用包含字符串的那些行作为标准来过滤数据帧RTB。我正在使用dplyr。d.del <- df %.%  group_by(TrackingPixel) %.%  summarise(MonthDelivery = as.integer(sum(Revenue))) %.%  arrange(desc(MonthDelivery))我知道我可以在其中使用该函数filter,dplyr但是我不完全知道如何告诉它检查字符串的内容。我尤其要检查列中的内容TrackingPixel。如果字符串包含标签,RTB我想从结果中删除该行。
查看完整描述

3 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

这个答案与其他答案相似,但是使用preferred stringr::str_detect和dplyr rownames_to_column。


library(tidyverse)


mtcars %>% 

  rownames_to_column("type") %>% 

  filter(stringr::str_detect(type, 'Toyota|Mazda') )


#>             type  mpg cyl  disp  hp drat    wt  qsec vs am gear carb

#> 1      Mazda RX4 21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4

#> 2  Mazda RX4 Wag 21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4

#> 3 Toyota Corolla 33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1

#> 4  Toyota Corona 21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1

由reprex软件包(v0.2.0)于2018-06-26创建。


查看完整回答
反对 回复 2019-10-14
  • 3 回答
  • 0 关注
  • 7604 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信