matchLengths: Resize vector to required length

View source: R/math.R

matchLengthsR Documentation

Resize vector to required length

Description

Internal soundgen function.

Usage

matchLengths(
  myseq,
  len,
  padDir = c("left", "right", "central")[3],
  padWith = 0
)

Arguments

myseq

input vector

len

target length

padDir

specifies the affected side. For padding, it is the side on which new elements will be added. For trimming, this is the side that will be trimmed. Defaults to 'central'

padWith

if the vector needs to be padded to match the required length, what should it be padded with? Defaults to 0

Details

Adjusts a vector to match the required length by either trimming one or both ends or padding them with zeros.

Value

Returns the modified vector of the required length.

Examples

soundgen:::matchLengths(c(1, 2, 3), len = 5)
soundgen:::matchLengths(3:7, len = 3)
# trimmed on the left
soundgen:::matchLengths(3:7, len = 3, padDir = 'left')
# padded with zeros on the left
soundgen:::matchLengths(3:7, len = 10, padDir = 'left')
#' # trimmed on the right
soundgen:::matchLengths(3:7, len = 3, padDir = 'right')
# padded with zeros on the right
soundgen:::matchLengths(3:7, len = 10, padDir = 'right')

soundgen documentation built on Sept. 12, 2024, 6:29 a.m.