Filter by ranges supplied by two vectors, without a join operation

后端 未结 2 1518
半阙折子戏
半阙折子戏 2021-01-12 11:23

I wish to do exactly this: Take dates from one dataframe and filter data in another dataframe - R

except without joining, as I am afraid that after I join my data th

2条回答
  •  日久生厌
    2021-01-12 11:37

    Maybe you could borrow the inrange function from data.table, which

    checks whether each value in x is in between any of the intervals provided in lower,upper.

    Usage:

    inrange(x, lower, upper, incbounds=TRUE)

    library(dplyr); library(data.table)
    
    tmp_df %>% filter(inrange(a, c(2,4), c(2,5)))
    #  a
    #1 2
    #2 4
    #3 5
    

提交回复
热议问题