addVectors: Add overlapping vectors

Description Usage Arguments Examples

View source: R/utilities_math.R

Description

Adds two partly overlapping vectors, such as two waveforms, to produce a longer vector. The location at which vector 2 is pasted is defined by insertionPoint. Algorithm: both vectors are padded with zeroes to match in length and then added. All NA's are converted to 0.

Usage

1
addVectors(v1, v2, insertionPoint)

Arguments

v1, v2

numeric vectors

insertionPoint

the index of element in vector 1 at which vector 2 will be insterted (any integer, can also be negative)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
v1 = 1:6
v2 = rep(100, 3)
addVectors(v1, v2, insertionPoint = 5)
addVectors(v1, v2, insertionPoint = -4)
# note the asymmetry: insertionPoint refers to the first arg
addVectors(v2, v1, insertionPoint = -4)

v3 = rep(100, 15)
addVectors(v1, v3, insertionPoint = -4)
addVectors(v2, v3, insertionPoint = 7)

tatters/soundgen_beta documentation built on May 14, 2019, 9 a.m.