Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering what are the differences between Mode, Class and Type of R objects? Type of a R object can be obtained by typeof() function, mode by mode(), and class by class().

Also any other similar functions and concepts that I missed?

Thanks and regards!

share|improve this question
str(variable) is your best friend. – Brandon Bertelsen Sep 30 '10 at 18:21
See also R: Types and classes of variables question on Stack Overflow. – Leo Nov 4 '12 at 17:16
up vote 19 down vote accepted

The class() is used to define/identify what "type" an object is from the point of view of object-oriented programming in R. So for

> x <- 1:3
> class(x)
[1] "integer"

any generic function that has an "integer" method will be used.

typeof() gives the "type" of object from R's point of view, whilst mode() gives the "type" of object from the point of view of Becker, Chambers & Wilks (1988). The latter may be more compatible with other S implementations according to the R Language Definition manual.

I'd probably err on the side of using typeof() in most cases unless it was for passing R objects to compiled code, where storage.mode() will be useful.

This is usefully discussed in the R Language Definition as linked to above.

share|improve this answer
Why there're so many points of view? I see no benefits but confusion. – smwikipedia Oct 10 '13 at 9:29
@smwikipedia because R has a heritage that includes S-Plus and S and that latter language evolved over time. Also, there is a need to differentiate between the objects users can create and the base object types. – Gavin Simpson Oct 10 '13 at 14:16
@smwikipedia because that's just how R is. For the same reason we have <- and = for variable assignment. – André Terra Oct 15 '15 at 17:56

From: :

'mode' is a mutually exclusive classification of objects according to their basic structure. The 'atomic' modes are numeric, complex, character and logical. Recursive objects have modes such as 'list' or 'function' or a few others. An object has one and only one mode.

'class' is a property assigned to an object that determines how generic functions operate with it. It is not a mutually exclusive classification. If an object has no specific class assigned to it, such as a simple numeric vector, it's class is usually the same as its mode, by convention.

Changing the mode of an object is often called 'coercion'. The mode of an object can change without necessarily changing the class.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.