Learn R Programming

cppcontainers (version 1.0.4)

resize: Alter the container size

Description

Alter the size of the container by reference.

Usage

resize(x, size, value = NULL)

Value

Invisibly returns NULL.

Arguments

x

A cppcontainers object.

size

The new size of the container.

value

The value of new elements. It defaults to 0 for integers and doubles, to "" for strings, and to FALSE for booleans.

Details

If the new size is larger than the former size, the function sets newly added elements in the back to value.

Examples

Run this code
v <- cpp_vector(4:9)
v
# 4 5 6 7 8 9

size(v)
# 6

resize(v, 10)
v
# 4 5 6 7 8 9 0 0 0 0

resize(v, 3)
v
# 4 5 6

Run the code above in your browser using DataLab