padzeros: Pad matrix with zeros

Description Usage Arguments Details Value Author(s) References Examples

View source: R/padzeros.R

Description

Adds zeros to the left side of a matrix or vector, to its right side, or to both sides.

Usage

1
padzeros(data, nzeros, side="both")

Arguments

data

the original matrix or vector

nzeros

number of columns to add on one side

side

to which side to add the zeros - choose between "both", "left" or "right"

Details

When data is a numeric vector, it is converted to a matrix of a single row.

Value

A matrix with the same number of rows as the original matrix, and extra columns containing zeros on the specified side or sides

Author(s)

Jan Gerretzen

References

Bloemberg, T.G., et al. (2010) "Improved parametric time warping for Proteomics", Chemometrics and Intelligent Laboratory Systems, 104 (1), 65 – 74.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
data(lcms)
lcms.z1 <- padzeros(lcms[75,,1], 250, side="left")
lcms.z2 <- padzeros(lcms[75,,1], 250, side="right")
lcms.z3 <- padzeros(lcms[75,,1], 250, side="both")
zeros <- rep(0, 250)

layout(matrix(1:4,2,2, byrow=TRUE))
plot(lcms[75,,1], type="l", main="Original signal")

plot(as.vector(lcms.z1), type="l", main="Padzeros left side")
points(1:250, zeros, col=2, lwd=0.08)

plot(as.vector(lcms.z2), type="l", main="Padzeros right side")
points(2001:2250, zeros, col=2, lwd=0.08)

plot(as.vector(lcms.z3), type="l", main="Padzeros both sides")
points(1:250, zeros, col=2, lwd=0.08)
points(2251:2500, zeros, col=2, lwd=0.08)

Example output



ptw documentation built on Jan. 19, 2022, 5:07 p.m.