Learn R Programming

soundgen (version 2.7.0)

matchLengths: Resize vector to required length

Description

Internal soundgen function.

Usage

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

Value

Returns the modified vector of the required length.

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.

Examples

Run this code
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')

Run the code above in your browser using DataLab