filter function in dplyr errors

前端 未结 4 803
终归单人心
终归单人心 2020-12-03 10:45

I have a data frame in R like so called UK_profiles:

row.names   id     name
1   1   8131437     Profile
2   2   8131719     WolverineCompetitio         


        
4条回答
  •  抹茶落季
    2020-12-03 11:00

    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
    

    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.

提交回复
热议问题