I have a dataset in a data.table
format that looks as such:
ID time.s time.e
1 1 2
2 1 4
3 2 3
4 2 4
I want to check to see if the value 1 is within time.s
and time.e
so that the end result would look like
[1] TRUE TRUE FALSE FALSE
How would I go about this? I have tried to use
a[1 %in% seq(time.s, time.e)]
But all I get is all TRUE values. Any recommendations?
In Excel, to check if a value exists in a range or not, you can use the COUNTIF function, with the IF function. With COUNTIF you can check for the value and with IF, you can return a result value to show to the user. i.e., Yes or No, Found or Not Found.
Return a value if a given value exists in a certain range by using a formula. Please apply the following formula to return a value if a given value exists in a certain range in Excel. 1. Select a blank cell, enter formula =VLOOKUP(E2,A2:C8,3, TRUE) into the Formula Bar and then press the Enter key.
Also, this works:
with(dat, time.s <= 1 & time.e >= 1)
Just adding to the tools that could be used to this, another being data.table::between
:
data.frame <- data.frame(ID = 1:4,
time.s = c(1,1,2,2),
time.e = c(2,4,3,4))
data.table::between(1, data.frame$time.s, data.frame$time.e)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With