Skip to contents

This function initializes a list based on size or names, with an optional initial value.

Usage

initList(x = NULL, initVal = NULL)

Arguments

x

A character vector as names, or an numeric indicating the size of the list.

initVal

an optional initial value for all elements of the list.

Value

A list of the specified size and names, optionally initialized with a value.

Examples

# Create a list with 3 elements
initList(3)
#> [[1]]
#> NULL
#> 
#> [[2]]
#> NULL
#> 
#> [[3]]
#> NULL
#> 
# Create a named list initialized with NULL
initList(c("a", "b", "c"))
#> $a
#> NULL
#> 
#> $b
#> NULL
#> 
#> $c
#> NULL
#> 
# Create a list with 2 elements initialized with 0
initList(2, 0)
#> [[1]]
#> [1] 0
#> 
#> [[2]]
#> [1] 0
#>