I have two data frames containing time series (with time encoded as numeric rather than temporary objects, and time is not sorted). I would like to normalize the response variable in one data frame to the response variable in another data frame. The problem is that the time points in two data frames are not completely equivalent. So, I need to combine two data frames according to the approximate coincidence of the two time columns.
The data is as follows:
df1 <- structure(list(t1 = c(3, 1, 2, 4), y1 = c(9, 1, 4, 16)), .Names = c("t1", "y1"), row.names = c(NA, -4L), class = "data.frame") df2 <- structure(list(t2 = c(0.9, 4.1), y2 = structure(1:2, .Label = c("a", "b"), class = "factor")), .Names = c("t2", "y2"), row.names = c(NA, -2L), class = "data.frame")
The result should look like this:
t1 y1 y2 1 1 a 4 16 b
It seems that approx or approxfun would be helpful, but I can't figure out how to do this.
source share