Reputation: 169
Is it possible in R to directly input a range of numerical values into a cell of a data frame (or some other data type) and have it return true if a number matches that cell?
I'm thinking something like:
A | B |
---|---|
n1 | 1-2 |
n2 | 3-5 |
n3 | 6-9 |
Then I want df[3,2] == 7 to return true.
Essentially what I want to do is return column A whenever a number falls within range specified by column B. I can think of complex solutions to do this, but I'm hoping I'm missing something easy and straightforward.
Upvotes: 0
Views: 472
Reputation: 740
df = data.frame(A = c("n1","n2","n3"))
df$B = list(1:2,3:5,6:9)
any(df[3,2][[1]] %in% 7)
Upvotes: 2