I'm working with R-Studio and want to get multiple rows from a data.table.
Let's say I have a data.table with the following data:
Date Column 1
"01.02.2016 10:00:00 CEST" 10
"01.02.2016 10:01:00 CEST" 12
"01.02.2016 10:02:00 CEST" 13
"01.02.2016 10:03:00 CEST" 11
"01.02.2016 10:04:00 CEST" 17
and I want to get the values from "01.02.2016 10:00:30" to "01.02.2016 10:02:30" like this:
Date Column 1
"01.02.2016 10:01:00 CEST" 12
"01.02.2016 10:02:00 CEST" 13
at the moment I achieve this by doing this:
x <- data.table[Date >= "01.02.2016 10:00:30 CEST" & Date <= "01.02.2016 10:02:30 CEST"]
But this is far too slow for me, because on a data.table with 600k rows it takes about 0.4 seconds.
Instead this is much much faster:
setkey(data.table, Date)
x <- prozessdaten.data.table[J(c("01.02.2016 10:01:00 CEST", "01.02.2016 10:02:00 CEST"))]
My Question is there a possibility to use the binary Search function J() with a specified time range and not exact values?
"01.02.2016 10:00:30" < "21.02.2015 10:02:30"
returns, for example - talat