Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pad

Pad data


Description

Pre- or postpad the data object x with the value c until it is of length l.

Usage

pad(x, l, c = 0, MARGIN = 2, direction = c("both", "pre", "post"))

prepad(x, l, c = 0, MARGIN = 2)

postpad(x, l, c = 0, MARGIN = 2)

Arguments

x

Vector or matrix to be padded

l

Length of output data along the padding dimension. If length (x) > l, elements from the beginning (dimension = "pre") or the end (direction = "post") of x are removed until a vector of length l is obtained. If direction = "both", values are removed from both ends, and in case of an uneven length the smallest number of elements is removed from the beginning of vector.

c

Value to be used for the padding (scalar). Must be of the same type as the elements in x. Default: 0

MARGIN

A vector giving the subscripts which the function will be applied over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns. Where x has named dimnames, it can be a character vector selecting dimension names. If MARGIN is larger than the dimensions of x, the result will have MARGIN dimensions. Default: 2 (columns).

direction

Where to pad the array along each dimension. One of the following:

"pre"

Before the first element

"post"

After the last element

"both"

(default) Before the first and after the last element

Value

Padded data, returned as a vector or matrix.

Author(s)

Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

Examples

v <- 1:24
res <- postpad(v, 30)
res <- postpad(v, 20)
res <- prepad(v, 30)
res <- prepad(v, 20)

m <- matrix(1:24, 4, 6)
res <- postpad(m, 8, 100)
res <- postpad(m, 8, 100, MARGIN = 1)
res <- prepad(m, 8, 100)
res <- prepad(m, 8, 100, MARGIN = 1)

res <- postpad(m, 2)
res <- postpad(m, 2, MARGIN = 1)
res <- prepad(m, 2)
res <- prepad(m, 2, MARGIN = 1)

gsignal

Signal Processing

v0.3-1
GPL-3
Authors
Geert van Boxtel [aut, cre] (Maintainer), Tom Short [aut] (Author of 'signal' package), Paul Kienzle [aut] (Majority of the original sources), Ben Abbott [ctb], Juan Aguado [ctb], Muthiah Annamalai [ctb], Leonardo Araujo [ctb], William Asquith [ctb], David Bateman [ctb], David Billinghurst [ctb], Juan Pablo Carbajal [ctb], André Carezia [ctb], Vincent Cautaerts [ctb], Eric Chassande-Mottin [ctb], Luca Citi [ctb], Dave Cogdell [ctb], Carlo de Falco [ctb], Carne Draug [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], R.G.H Eschauzier [ctb], Andrew Fitting [ctb], Alan J. Greenberger [ctb], Mike Gross [ctb], Daniel Gunyan [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Jake Janovetz [ctb], Alexander Klein [ctb], Peter V. Lanspeary [ctb], Bill Lash [ctb], Friedrich Leissh [ctb], Laurent S. Mazet [ctb], Mike Miller [ctb], Petr Mikulik [ctb], Paolo Neis [ctb], Georgios Ouzounis [ctb], Sylvain Pelissier [ctb], Francesco Potortì [ctb], Charles Praplan [ctb], Lukas F. Reichlin [ctb], Tony Richardson [ctb], Asbjorn Sabo [ctb], Thomas Sailer [ctb], Rolf Schirmacher [ctb], Rolf Schirmacher [ctb], Ivan Selesnick [ctb], Julius O. Smith III [ctb], Peter L. Soendergaard [ctb], Quentin Spencer [ctb], Doug Stewart [ctb], P. Sudeepam [ctb], Stefan van der Walt [ctb], Andreas Weber [ctb], P. Sudeepam [ctb], Andreas Weingessel [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.