How to deal with mixed objects in R



I was creating a vector of a numeric and logical in R I am supposing that I will get the error but I am getting no error and when I have checked the class I am getting the numeric but I am unable to understand it
[1] “numeric”


Hello @sid100158,

As you can see above the v2 vector is of character class.R coerces elements in a vector depending upon the values it holds.In the above example as you can see 2 has been coerced into a character.So in your case the T is coerced from logical to numeric whereas in:
it has been coerced into character.My guess is that character has the highest priority,meaning if a vector has a character variable all the others are converted into character.Numeric has the next highest priority.
Hope this helps!!


logical can be coerced to numeric (1,0)


[1] 1 2