How to merge two data frames in r by a common column with mismatched date/time values

前端 未结 2 942
天命终不由人
天命终不由人 2020-12-10 21:44

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:



        
2条回答
  •  我在风中等你
    2020-12-10 22:07

    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

提交回复
热议问题