Q:

R: filter %in% range not filtering values with decimals

I have a dataset e:
`structure(list(num = c(23L, 23L, 23L), code = structure(1:3, .Label = c("A", 
"B", "C"), class = "factor"), ranking = c(140.5, 140.5, 
2662), bottom = c(-0.0207357225475016, -0.0146710913954366, 
-0.019899240924872), previous = c(0.00312288516116536, 
0.00207118230618904, -0.00191931365721628), mean_of_all = c(-0.000222419352160109, 
-0.00107348087538642, -0.00202343390338765)), row.names = c(NA, 
-3L), class = "data.frame")`

code:
`winner_filtered <- e %>%
        group_by(code) %>%
        filter(ranking %in% (winner_lower:winner_upper))`

is not filtering the two values with 140.5
Any guesses? Thanks.

A:

As the column 'ranking' is numeric, it may not exactly be equal to the values generated from the sequence due to precision.  So, the filter can be either with <, > operators or use a convenient wrapper between
library(dplyr)
e %>%
    group_by(code) %>%
    filter(between(ranking, winner_lower, winner_upper))

