Skip to content
Prev 315604 / 398503 Next

function approx interpolation of time series data sets

Hello,

Both Gabor's and my way work and produce the same results:


#-- Gabor
library(zoo)
library(chron)

data1 <- "
01:23:40  5
01:23:45 10
01:23:50 12
01:23:55  7"

data2 <- "
01:23:42
01:23:47
01:23:51
01:23:54
01:23:58
01:23:59"

data1zoo <- read.zoo(text=data1, FUN=times)
data2zoo <- read.zoo(text=data2, FUN=times)
na.approx(data1zoo, xout = time(data2zoo))

#-- Rui

data1 <- read.table(text = "
01:23:40 5
01:23:45 10
01:23:50 12
01:23:55 7
")

data2 <- read.table(text = "
01:23:42
01:23:47
01:23:51
01:23:54
01:23:58
01:23:59
")

approx(as.POSIXct(data1$V1, format = "%H:%M:%S"),
	y = data1$V2,
	xout = as.POSIXct(data2$V1, format = "%H:%M:%S"))


Note that the last two values of data2 are outside the range of data1, 
and therefore the interpolation functions return nothing 
(zoo::na.approx) or NA (stats::approx)

Hope this helps,

Rui Barradas

Em 18-01-2013 13:51, e-letter escreveu: