Convert values of an Object to Logical Vector in R Programming – as.logical() Function
Last Updated :
08 Nov, 2021
as.logical() function in R Language is used to convert an object to a logical vector.
Syntax: as.logical(x)
Parameters:
x: Numeric or character object
R – as.logical() Function Example
Example 1: Basic example of as.logical() Function in R Programming Language.
R
x <- c (1, 2, 3, 0, 1.4, NA )
as.logical (T)
as.logical ( "F" )
as.logical (2)
as.logical (x)
|
Output:
[1] TRUE
[1] FALSE
[1] TRUE
[1] TRUE TRUE TRUE FALSE TRUE NA
Example 2: Multiple objects with as.logical() Function in R.
R
x1 <- matrix ( c (1:4), 2, 2)
x2 <- matrix ( c (2, 0, 1, 1.3), 2, 2)
as.logical (x1)
as.logical (x2)
|
Output:
[1] TRUE TRUE TRUE TRUE
[1] TRUE FALSE TRUE TRUE
Share your thoughts in the comments
Please Login to comment...