I wish to merge two datasets using ‘date time’ columns that are present in both (POSIXct format: dd/mm/yyyy hh:mm). Below is example data from the two datasets:
The selector of data.table seems well suited for that. It is really efficient and allow to merge the nearest value (upper or lower or both).
Find on this website: https://www.r-bloggers.com/understanding-data-table-rolling-joins/ example for left, right joins...etc
website[, join_time:=session_start_time]
paypal[, join_time:=purchase_time]
setkey(website, name, join_time)
setkey(paypal, name, join_time)
website[paypal, roll = T]
About DT: https://cran.r-project.org/web/packages/data.table/vignettes/datatable-intro.html