Learn R Programming

rinform (version 1.0.2)

resize: Resize

Description

Generic function to resize the support of the distribution in place. If the distribution shrinks, the last lenght(Dist) - n elements are lost, the rest are preserved. If it grows, the last n - lenght(Dist) elements are zeroed.

Usage

resize(d, n)

Arguments

d

Dist object representing the distribution.

n

Numeric representing the desired size of the support.

Value

Dist giving the resized distribution.

Examples

Run this code
# NOT RUN {
# Resizing invalid distribution
d <- Dist(5)
d <- resize(d, 3)
length(d) # 3

d <- resize(d, 8)
length(d) # 8

# Resizing valid distribution
d <- Dist(c(1, 2, 3, 4))
d <- resize(d, 2) # list(c(1, 2), 2, 3)
d
d <- resize(d, 4) # list(c(1, 2, 0, 0), 4, 3)
d
# }

Run the code above in your browser using DataLab