Home > Enterprise >  Can the elements of vector belong to different classes in R?
Can the elements of vector belong to different classes in R?

Time:11-03

I have just started R programming language and this is something I wanted to clear it up. can someone explain this. or Is it that the elements must belong to the same class?

I have read articles about this, but is still confusing so turning to the community

CodePudding user response:

Try it for yourself:

v = c(1,2,'3')

This might make you think R accepts multiple classes, but if you print it, you get the following:

[1] "1" "2" "3"

They're all strings. So, no, you might type a vector with multiple classes, but R will try to turn it into a common class.

  • Related