How to deal with mixed objects in R

r

#1

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
y<-c(T,2)
class(y)
[1] “numeric”


#2

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!!


#3

logical can be coerced to numeric (1,0)

see

y=c(T,2)
y
[1] 1 2