Learn R Programming

JWileymisc (version 1.4.1)

as.na: Coerces vectors to missing

Description

Given a vector, convert it to missing (NA) values, where the class of the missing matches the input class. Currently supports character, logical, integer, factor, numeric, times (from chron), Date, POSIXct, POSIXlt, and zoo (from zoo).

Usage

as.na(x)

Value

a vector the same length as the input with missing values of the same class

Arguments

x

A vector to convert to missing (NA)

Examples

Run this code
str(as.na(1L:5L))
str(as.na(rnorm(5)))
str(as.na(c(TRUE, FALSE)))
str(as.na(as.Date("2017-01-01")))

Run the code above in your browser using DataLab