logical {base}

Description

Create or test for objects of type "logical", and the basic logical constants.

Usage

TRUE
FALSE
T; F
logical(length = 0)
as.logical(x, ...)
is.logical(x)

Arguments

length

A non-negative integer specifying the desired length. Double values will be coerced to integer: supplying an argument of length other than one is an error.

x

object to be coerced or tested.

...

further arguments passed to or from other methods.

Details

TRUE and FALSE are reserved words denoting logical constants in the R language, whereas T and F are global variables whose initial values set to these. All four are logical(1) vectors.

Logical vectors are coerced to integer vectors in contexts where a numerical value is required, with TRUE being mapped to 1L, FALSE to 0L and NA to NA_integer_.

Values

logical creates a logical vector of the specified length. Each element of the vector is equal to FALSE.

as.logical attempts to coerce its argument to be of logical type. For factors, this uses the levels (labels). Like as.vector it strips attributes including names. Character strings c("T","TRUE","True","true") are regarded as true, c("F","FALSE","False","false") as false, and all others as NA.

is.logical returns TRUE or FALSE depending on whether its argument is of logical type or not.

References

See Also

Search Language Reference

Search this site:

About Language Reference

This is a collection of the help pages from every function and dataset in the latest version of R (base and recommended packages). Add your comments to the page to offer tips for using these functions, or expand on the documentation. Your comments are tagged with the current R version number, and will be preserved when these pages are updated with the next R release.

The URLs for these pages are stable, in the format:http://www.inside-r.org/r-doc/PACKAGE/FUNCTION

Feel free to link to them from other pages.

About inside-R.org

inside-R.org is a collection of resources about the open-source R Project for the R Statistics Community. This site is sponsored by Revolution Analytics.