Re: [R] Matching Dates Closest without going over

2009-10-10 Thread ampc
Thanks Gabor. That was exactly what I was looking for. Ampy ampc wrote: > > Hi, > > I have 2 date vectors d1 and d2. > > d1 <- structure(c(14526, 14495, 14464, 14433, 14402, 14371, 14340, 14309, > 14278, 14247, 14216, 14185), class = "Date") > d2 <- structure(c(14526, 14509, 14488, 1446

Re: [R] Matching Dates Closest without going over

2009-10-10 Thread Gabor Grothendieck
Create two zoo series, merge them and use na.locf (last occurence carried forward): library(zoo) z1 <- zoo(as.numeric(d1), d1) z2 <- zoo(as.numeric(d2), d2) z <- merge(z1, z2) z.na.locf <- na.locf(z, na.rm = FALSE)[time(z1)] transform(as.data.frame(z.na.locf), z1 = as.Date(z1), z2 = as.Date(z2))

[R] Matching Dates Closest without going over

2009-10-09 Thread ampc
Hi, I have 2 date vectors d1 and d2. d1 <- structure(c(14526, 14495, 14464, 14433, 14402, 14371, 14340, 14309, 14278, 14247, 14216, 14185), class = "Date") d2 <- structure(c(14526, 14509, 14488, 14466, 14453, 14441, 14396, 14388, 14343, 14333, 14310, 14281), class = "Date") I would like to cre