Skip to contents

For a given type and length, create a vector of NA's.

Usage

na.vector(
  length = 1L,
  type = c("logical", "integer", "double", "character", "complex", "numeric", "list")
)

Arguments

length

integer, length of the output vector.

type

character string naming an atomic type that has an equivalent NA value (i.e., not raw), or "list".

Value

vector of given mode and length filled with NA values.

Details

This function also offers a "list" type, which gives a list of single (logical) NA values. To initialize an empty list of a given length, use empty.list instead.

See also

Examples

na.vector(5L)
#> [1] NA NA NA NA NA
x <- na.vector(3L, "character")
class(x)
#> [1] "character"

x <- complex(1:5, 6:10)
y <- na.vector(length(x), typeof(x))
class(y)
#> [1] "complex"
length(y)
#> [1] 5

na.vector(2L, "list")
#> [[1]]
#> [1] NA
#> 
#> [[2]]
#> [1] NA
#>