I have two datasets that I would like to join based on the timestamp range. The timestamp doesn't always match in both data frames. Therefore, I would like to join based on a range. I have been advised to us foverlaps.
I'm using this code below but it isn't working not sure how to fulfill all the parameters:
require(data.table)
simple example:
x = data.table(df2,start=c(timestamp),end=c(taskId))
y = data.table(df1,start=c(timestamp),end=c(gpuMemUtilPerc))
setkey(y,start,end)
foverlaps(x, y, by.x = c("timestamp","hostname"), type="within", nomatch = 0L)
error message:
Error in foverlaps(x, y, by.x = c("timestamp", "hostname"), type = "within", :
The last two columns in by.x should correspond to the 'start' and 'end' intervals in data.table 'x' and must be integer/numeric type.
DF2
tibble::tribble(
~timestamp, ~hostname, ~eventName, ~eventType, ~jobId, ~taskId,
"2018-11-08T07:41:45.459Z", "04dc4e9647154250beeee51b866b0715000000", "TotalRender", "START", "1024-lvl12-7e026be3-5fd0-48ee-b7d1-abd61f747705", "00390eee-c26c-41da-a02d-556bb7fcac67",
"2018-11-08T07:41:45.459Z", "04dc4e9647154250beeee51b866b0715000000", "Saving Config", "START", "1024-lvl12-7e026be3-5fd0-48ee-b7d1-abd61f747705", "00390eee-c26c-41da-a02d-556bb7fcac67",
"2018-11-08T07:41:32.461Z", "04dc4e9647154250beeee51b866b0715000000", "Render", "START", "1024-lvl12-7e026be3-5fd0-48ee-b7d1-abd61f747705", "00390eee-c26c-41da-a02d-556bb7fcac67",
"2018-11-08T07:41:32.461Z", "04dc4e9647154250beeee51b866b0715000000", "Saving Config", "STOP", "1024-lvl12-7e026be3-5fd0-48ee-b7d1-abd61f747705", "00390eee-c26c-41da-a02d-556bb7fcac67",
"2018-11-08T07:42:09.344Z", "04dc4e9647154250beeee51b866b0715000000", "Render", "STOP", "1024-lvl12-7e026be3-5fd0-48ee-b7d1-abd61f747705", "00390eee-c26c-41da-a02d-556bb7fcac67"
)
DF1
tibble::tribble(
~timestamp, ~hostname, ~gpuSerial, ~gpuUUID, ~powerDrawWatt, ~gpuTempC, ~gpuUtilPerc, ~gpuMemUtilPerc,
"2018-11-08T07:41:44.242Z", "04dc4e9647154250beeee51b866b0715000000", 323217056165, "GPU-a1119ee9-9cd1-919f-a479-b902142c717d", 25.94, 32L, 0L, 0L,
"2018-11-08T07:41:47.259Z", "04dc4e9647154250beeee51b866b0715000000", 323217056165, "GPU-a1119ee9-9cd1-919f-a479-b902142c717d", 25.84, 32L, 0L, 0L,
"2018-11-08T07:41:31.285Z", "04dc4e9647154250beeee51b866b0715000000", 323217056165, "GPU-a1119ee9-9cd1-919f-a479-b902142c717d", 25.84, 32L, 0L, 0L,
"2018-11-08T07:41:33.301Z", "04dc4e9647154250beeee51b866b0715000000", 323217056165, "GPU-a1119ee9-9cd1-919f-a479-b902142c717d", 25.94, 32L, 0L, 0L,
"2018-11-08T07:41:35.322Z", "04dc4e9647154250beeee51b866b0715000000", 323217056165, "GPU-a1119ee9-9cd1-919f-a479-b902142c717d", 25.84, 32L, 0L, 0L
)