Learn R Programming

LifeInsuranceContracts (version 0.0.4)

pad0: Pad a vector with 0 to a desired length

Description

Pad a vector with 0 to a desired length

Usage

pad0(v, l, value = 0, start = 0)

Value

returns the vector v padded to length l with value value (default 0).

Arguments

v

the vector to pad with 0

l

the desired (resulting) length of the vector

value

the value to pad with (if padding is needed). Default to 0, but can be overridden to pad with any other value.

start

the first start values are always set to 0 (default is 0), the vector v starts only after these leading zeroes. The number of leading zeroes counts towards the desired length

Examples

Run this code
pad0(1:5, 7)   # Pad to length 7 with zeroes
pad0(1:5, 3)   # no padding, but cut at length 3

# 3 leading zeroes, then the vector start (10 elements of vector, no additional padding needed):
pad0(1:10, 13, start = 3)

# padding with value other than zero:
pad0(1:5, 7, value = "pad")

Run the code above in your browser using DataLab