How does explicit coercion works in R?

193 views Asked by At

I am trying to understand the COERCION in R programming language. When it comes to explicit coercion, it states that we can convert from one class of vectors(considering general object) to another class.

Consider following,

> x <- c(1L, 0L, 3L)
> class(x)
[1] "integer"

So the class of x is integer here. Now we can convert it to logical as,

> as.logical(x)
[1]  TRUE FALSE  TRUE

So now the class of x should be logical as per the coercion, but when I again display the class of x as follows,

> as.logical(x)
[1]  TRUE FALSE  TRUE
> class(x)
[1] "integer"

How it is working? Please help me in understanding. And please correct my sentence "So now the class of x should be logical as per the coercion"

0

There are 0 answers