Learn R Programming

DecomposeR (version 1.0.2)

respace: Interpolate with even spacing

Description

Interpolate with even spacing. Can determine on its own the most conservative sampling interval (using the Greatest Common Rational Divisor)

Usage

respace(dt, xy = NULL, delta = NULL, tolerance = 8, relative = TRUE)

Arguments

dt

depth/time (same length than length/rows of xy)

xy

signal (vector or matrix)

delta

the new sampling interval. If NA, uses the Greatest Common Rational Divisor

tolerance, relative

parameters for the divisor function (StratigrapheR package), to compute the Greatest Common Rational Divisor

Value

a list of interpolated xy and dt values ($xy and $dt), plus a vector of logicals indicating whether each point was part of the initial input or was added by interpolation

Examples

Run this code
# NOT RUN {
set.seed(42)

n <- 50
t <- seq_len(n)

xy <- (1 + 0.6 * sin(t*0.025)) * sin(t*0.2)  + 2 * sin(t*0.025) +
        rnorm(n, sd = 0.5)

inter_dt <- round(runif(length(xy), min = 0.5, max = 1.5), 1)

dt <- cumsum(inter_dt)

res <- respace(xy = xy, dt = dt)

opar <- par("mfrow")

par(mfrow = c(1,1))

plot(res$xy, res$dt, type = "l")
points(res$xy[res$initial], res$dt[res$initial], pch = 19, col = "green")
points(res$xy[!res$initial], res$dt[!res$initial],
       pch = 19, col = "red", cex = 0.5)

par(mfrow = opar)

# }

Run the code above in your browser using DataLab