pad: Pad vector with values

Description Usage Arguments Details Value Author(s) References Examples

Description

Append the atomic value val to the vector x until it is of length l.

Usage

1
2
  postpad(x, l, val = 0)
  prepad(x, l, val = 0) 

Arguments

x

The vector to append values to.

l

The resulting length of the vector after appending.

val

The scalar value to append.

Details

Postpad appends the value val to the end of vector x until it has length l. Prepad appends the value val to the beginning of vector x until it has length l.

If the length of x is greater than l, elements of x are removed until a vector of length l is obtained. The function postpad removes elements from the end of the vector; the function prepad removes values from the beginning of the vector.

This function removes the "dim" attribute of x, if present.

Value

A vector of length l. If x and val are not of the same type, implicit type conversion rules apply, see references.

Author(s)

Geert van Boxtel

References

https://www.r-bloggers.com/type-conversion-and-you-or-and-r/.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- 1:12
postpad(x, 15)
postpad(x, 10)
prepad(x, 15)
prepad(x, 10)
  
dim(x) <- c(3,4)
postpad(x, 10)
prepad(x, 15)
prepad(x, 10)

gjmvanboxtel/DSPutils documentation built on May 18, 2019, 2:35 p.m.