0
votes

DF1:

  a  b
1 1  6
2 2  7
3 3  8
4 4  9
5 5 10

DF2:

  c
1 3
2 8
3 4
4 2
5 9

I would like to see if each row of DF2 (column c) is between a & b in DF1; Hence the resulting filtering will be:

  c
1 3
3 4
5 9

How should this be done? I have a very long DF2 and a short DF1 I am trying this but get the following error:

library(tidyverse)
> c %>%
    filter(c>a & c<b)

Error in filter_impl(.data, quo) : Result must have length 5, not 10 In addition: Warning message: In c < b : longer object length is not a multiple of shorter object length

1
Please include the names of any packages you are using in your question. - lmo

1 Answers

1
votes
> library(dplyr)
> df1 <- data.frame (a = c(1,2,3,4,5), b = c(6,7,8,9,10))
> df2 <- data.frame (c = c(3,8,4,2,9))
> 
> df2 %>% filter(c > df1$a & c < df1$b)
  c
1 3
2 4
3 9