The language R confuses me. Entities have modes and classes, but even this is insufficient to fully describe the entity.
This answer says
In R every 'object' has a mode and a class.
So I did these experiments:
> class(3)  "numeric" > mode(3)  "numeric" > typeof(3)  "double"
Fair enough so far, but then I passed in a vector instead:
> mode(c(1,2))  "numeric" > class(c(1,2))  "numeric" > typeof(c(1,2))  "double"
That doesn't make sense. Surely a vector of integers should have a different class, or different mode, than a single integer? My questions are:
- Does everything in R have (exactly one) class ?
- Does everything in R have (exactly one) mode ?
- What, if anything, does 'typeof' tell us?
- What other information is needed to fully describe an entity? (Where is the 'vectorness' stored, for example?)
Update: Apparently, a literal 3 is just a vector of length 1. There are no scalars. OK But... I tried
mode("string") and got
"character", leading me to think that a string was a vector of characters. But if that was true, then this should be true, but it's not!
c('h','i') == "hi"