Lookup values corresponding to the closest date

后端 未结 2 1226
时光说笑
时光说笑 2020-12-22 09:05

I have a data.frame x with date and Value

x = structure(list(date = structure(c(1376534700, 1411930800, 1461707400, 
1         


        
2条回答
  •  离开以前
    2020-12-22 09:49

    Using data.table you can join to the nearest value

    library(data.table)
    
    x <- as.data.table(x)
    y <- data.table(date=y)
    
    res <- x[y, on='date', roll='nearest']
    

提交回复
热议问题