I have data.frame xwith dateandValue
x = structure(list(date = structure(c(1376534700, 1411930800, 1461707400,
1478814300, 1467522000, 1451088000, 1449956100, 1414214400, 1472585400,
1418103000, 1466176500, 1434035100, 1442466300, 1410632100, 1448571900,
1439276400, 1468382700, 1476137400, 1413177300, 1438881300), class = c("POSIXct",
"POSIXt"), tzone = ""), Value = c(44L, 49L, 31L, 99L, 79L, 92L,
10L, 72L, 60L, 41L, 28L, 21L, 67L, 61L, 8L, 65L, 40L, 48L, 53L,
90L)), .Names = c("date", "Value"), row.names = c(NA, -20L), class = "data.frame")
and another list ywith onlydate
y = structure(c(1470356820, 1440168960, 1379245020, 1441582800, 1381753740
), class = c("POSIXct", "POSIXt"), tzone = "")
Before trying to do this with a loop, I need to find out if there is a quick way (or packages) to search Valuefrom the nearest date to xfor dates in y? The goal is to find datein xwhich is closest to datein yand get the appropriate one Value.
The desired result (obtained from Excel VLOOKUP, therefore, may not be ideal) would be something like this:
output = structure(list(y = structure(c(1470356820, 1440168960, 1379245020,
1441582800, 1381753740), class = c("POSIXct", "POSIXt"), tzone = ""),
Value = c(40, 65, 44, 65, 44)), .Names = c("y", "Value"), row.names = c(NA,
-5L), class = "data.frame")