问题描述
我在R中有一个数据框,就像所谓的 UK_profiles
:
I have a data frame in R like so called UK_profiles
:
row.names id name
1 1 8131437 Profile
2 2 8131719 WolverineCompetition
3 4 8132011 www.vaseline.com
4 10 23265829 www.keepingskinamazing.co.uk
5 23 8042743 Mobile
6 24 8043312 Test
7 25 90914664 Join Our Core
8 26 45272695 UDF
9 27 50547829 apps.euro-bureau.eu/fairathon
10 28 50916438 www.benjerry.intashop.com/
11 44 83667343 All Web Site Data
12 45 84556272 UK
使用dplyr我希望过滤
并使用 grepl
删除行:
Using dplyr I wish to filter
and delete rows with grepl
using:
require(dplyr)
UK_profiles.filtered <- filter(UK_profiles, !grepl("Rollup|Microsite|Mobile|Test|tset|Profile|Facebook|Unfiltered|returnurl", name))
但是,我收到一条错误消息:
However, I get an error saying:
对象名称。
我也得到:
对象'name'
显然在数据框中。有人可以帮忙吗?
The object 'name'
is clearly in the dataframe. Can someone please help?
推荐答案
似乎您正在获取 stats :: filter
函数而不是 dplyr
函数。为了确保您选择的是正确的,请使用符号 dplyr :: filter
。
It does seem like you are getting the stats::filter
function and not the dplyr
one. To make sure you get the right one, use the notation dplyr::filter
.
d = data.frame(x=1:10,
name=c("foo","bar","baz","bar","bar","baz","fnord","qar","qux","quux"))
filter(d, !grepl("ar|ux", name))
Error in grepl("ar|ux", name) : object 'name' not found
dplyr::filter(d, !grepl("ar|ux", name))
x name
1 1 foo
2 3 baz
3 6 baz
4 7 fnord
您甚至不需要执行 library(dplyr)
即可工作-您确实需要安装 dplyr
You don't even need to do library(dplyr)
for this to work - you do need dplyr
installed though.
此功能适用于任何软件包中的功能。
This works for functions from any package.
这篇关于dplyr错误中的过滤器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!