The class
of an object does not have to be the same as the storage mode of the elements of that object. From the help page for class
:
Many R objects have a class attribute, a character vector giving the names of the classes from which the object inherits. If the object does not have a class attribute, it has an implicit class, "matrix", "array" or the result of mode(x) (except that integer vectors have implicit class "integer").
So if you do:
y <- as.difftime( c(0.5,1,2), units='mins' )
# 'typeof' determines the (R internal) type or storage mode of any object
typeof( y )
# [1] "double"
# And mode: Modes have the same set of names as types (see typeof) except that
# types "integer" and "double" are returned as "numeric".
mode( y )
# [1] "numeric"
class
is a programming construct, which allows you to do something like this:
# Integer vector
x <- 1:5
# Set the class with 'class<-'
class(x) <- "foo"
# Which is correctly returned by 'class'
class(x)
# [1] "foo"
# But our elements are still integers...
typeof(x)
[1] "integer"