R-.
install.packages, . , textConnection(Lines1) textConnection(Lines2) - "myfile1.dat" "myfile2.dat", , .
It reads the data that creates the zoo object zand the date vector dt. It then combines zwith the zoo object with a zero width (i.e., has dates but not data) whose date index is made from dt. na.locf(the last observation moves forward) fills in the missing values in the reverse order, sincefromLast = TRUE
Lines1 <- "Date Price
1/3/2000 10.00
1/5/2000 10.45
1/7/2000 10.25"
Lines2 <- "Date
1/1/2000
1/2/2000
1/3/2000"
library(zoo)
library(chron)
z <- read.zoo(textConnection(Lines1), header = TRUE, FUN = as.chron)
dt <- as.chron(scan(textConnection(Lines2), skip = 1, what = ""))
na.locf(merge(z, zoo(, dt)), fromLast = TRUE)
Result:
> na.locf(merge(z, zoo(, dt)), fromLast = TRUE)
01/01/00 01/02/00 01/03/00 01/05/00 01/07/00
10.00 10.00 10.00 10.45 10.25
There are three vignettes (PDF documents) that come with the zoo package and R News 4/1. The help desk has information and links to dates.
source
share