The first vector serves as a reference, the second vector is shifted, such that it aligns best with the first and has the same length as the first vector.

do_align(y1, y2, min.overlap = 0.1 * max(length(y1), length(y2)))

Arguments

y1

vector of striation marks (assuming equidistance between values)

y2

vector of striation marks

min.overlap

integer value: what is the minimal number of values between y1 and y2 that should be considered?

Value

list consisting of a) the maximal cross correlation, b) the lag resulting in the highest cross correlation, and c) a vector of length y1 with aligned values of y2.

Examples

library(dplyr) x <- runif(20) do_align(x, lead(x, 5))
#> Warning: min.overlap should not be below 3 values
#> $ccf #> [1] 1 #> #> $lag #> [1] -13 #> #> $y2 #> [1] 0.6118524 0.1725588 NA NA NA NA NA #> [8] NA NA NA NA NA NA NA #> [15] NA NA NA NA NA NA #>
do_align(x, lag(x, 5), min.overlap=2)
#> Warning: min.overlap should not be below 3 values
#> $ccf #> [1] 1 #> #> $lag #> [1] -18 #> #> $y2 #> [1] 0.24471823 0.04461716 NA NA NA NA #> [7] NA NA NA NA NA NA #> [13] NA NA NA NA NA NA #> [19] NA NA #>
do_align(x, lag(x, 5), min.overlap=3)
#> $ccf #> [1] 1 #> #> $lag #> [1] -5 #> #> $y2 #> [1] 0.86735020 0.24853870 0.40288121 0.76963018 0.11948537 0.19469496 #> [7] 0.16456925 0.66320658 0.85657500 0.92654645 0.55237759 0.57706569 #> [13] 0.68744775 0.24471823 0.04461716 NA NA NA #> [19] NA NA #>
do_align(x, x[-(1:5)], min.overlap=3)
#> $ccf #> [1] 1 #> #> $lag #> [1] 5 #> #> $y2 #> [1] NA NA NA NA NA 0.19469496 #> [7] 0.16456925 0.66320658 0.85657500 0.92654645 0.55237759 0.57706569 #> [13] 0.68744775 0.24471823 0.04461716 NA NA NA #> [19] NA NA #>
do_align(x[-(1:5)], x, min.overlap=3)
#> $ccf #> [1] 1 #> #> $lag #> [1] -5 #> #> $y2 #> [1] 0.19469496 0.16456925 0.66320658 0.85657500 0.92654645 0.55237759 #> [7] 0.57706569 0.68744775 0.24471823 0.04461716 0.90985456 0.07068122 #> [13] 0.99689147 0.61185242 0.17255885 #>