dplyr 错误中的过滤功能 [英] filter function in dplyr errors

查看:25
本文介绍了dplyr 错误中的过滤功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 我希望 filter 并使用 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:

未找到对象名称".

我也得到:

在 data.matrix(data) 中:强制引入的 NAs.

In data.matrix(data) : NAs introduced by coercion.

对象 '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 错误中的过滤功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆