Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R dplyr filter not working right with mildly complex filter

Tags:

r

dplyr

dplyr filter not working when I have a list subsetting in the check Value. Samething works when I assign to to variable. See code below

df1<-data.frame(x=1:26, y=letters, stringsAsFactors = F)
templist<-list(alpha=df1)
res<-df1 %>% filter(y %in% templist$alpha$y)
nrow(res)
[1] 0
tempLetters <- templist$alpha$y
res<-df1 %>% filter(y %in% tempLetters)
nrow(res)
[1] 26

I thought this used to work earlier. Please help. Note that the column names are same in both (y) by design.

I have updated dplyr, tidyr, pipeR to the latest versions on cran just now (4 jan, 2017)

like image 337
guna Avatar asked Jan 04 '17 10:01

guna


People also ask

Can you use filter in dplyr?

Of course, dplyr has 'filter()' function to do such filtering, but there is even more. With dplyr you can do the kind of filtering, which could be hard to perform or complicated to construct with tools like SQL and traditional BI tools, in such a simple and more intuitive way.

How do I filter multiple values in R dplyr?

In this, first, pass your dataframe object to the filter function, then in the condition parameter write the column name in which you want to filter multiple values then put the %in% operator, and then pass a vector containing all the string values which you want in the result.

How do I filter out my dplyr?

You can use the following basic syntax in dplyr to filter for rows in a data frame that are not in a list of values: df %>% filter(! col_name %in% c('value1', 'value2', 'value3', ...))


1 Answers

@hadleywickham has confirmed that this is a known bug fixed in dev

Pls see his response on twitter at: https://twitter.com/gunapemmaraju/status/816639470166544384

like image 91
guna Avatar answered Oct 04 '22 21:10

guna