Learn R Programming

labelr (version 0.1.9)

check_class: Determine If Vector Belongs to Any of Specified Classes

Description

check_class determines whether a vector's class is among those specified.

Usage

check_class(
  x,
  classes = c("numeric", "integer", "logical", "character", "factor", "ordered"),
  strict = TRUE
)

Value

a 1L logical vector indicating whether x's class is found among those passed to the classes argument.

Arguments

x

the vector to check against specified classes.

classes

a character vector of classes against which x is checked.

strict

If TRUE, all of x's classes must be among those specified in the classes argument. If FALSE, at least one but not necessarily all of x's classes must be among those specified in the classes argument.

Details

By default (strict = TRUE), if a vector is of multiple classes, all of its classes must be among those specified via the classes argument.

Examples

Run this code
check_class(mtcars$mpg) # TRUE
check_class(mtcars$mpg, classes = c("numeric", "factor")) # TRUE
check_class(iris$Species) # TRUE
check_class(iris$Species, classes = c("logical", "numeric")) # FALSE
check_class(mtcars$mpg, classes = c("logical", "character", "factor")) # FALSE

Run the code above in your browser using DataLab