The class numeric includes sub-classes integer and double. The interesting thing is that the class of a variable depends on the way it is initialised. For example:
x <- c(0,0,0,0,0,1,1,1,1,1)
y <- rep(0:1, c(5,5))
x
# [1] 0 0 0 0 0 1 1 1 1 1
y
# [1] 0 0 0 0 0 1 1 1 1 1
class(x)
# [1] "numeric"
class(y)
# [1] "integer"
identical(x,y)
# [1] FALSE
My question: why does R not coerce x in the example to class integer? I think it would make more sense to do so as x is an integer and a numeric vector, but a numeric vector is not necessarily a vector of integers. Hence, coercing x to be of the integer class might be more intuitive, at least for me. Am I missing something?
