title: What is the difference between mode and class in R?
body: <p>I am learning R (I started just this week), and I've been struggling with the concepts of typeof, mode, storage.mode and class. I've been searching up and down (official R documentation, StackOverflow, Google, etc.), and I haven't been able to find any clear explanation of the difference between these. (A few <a href="https://stackoverflow.com/questions/11881662/the-class-and-mode-of-a-matrx">StackOverflow</a> <a href="https://stackoverflow.com/questions/24052158/in-r-why-is-matrix-a-class-but-a-vector-is-not">and</a> <a href="https://stats.stackexchange.com/questions/3212/mode-class-and-type-of-r-objects">CrossValidated</a> answers have not really helped clear me up.) Finally (I hope), I think I understand it, and so my question is to verify if my understanding is correct.</p>
  
  <p><strong>mode vs storage.mode:</strong> <a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/mode.html" rel="noreferrer">mode and storage.mode are basically the same thing</a>, except for a tiny difference in how the "single" datatype is handled.</p>
  
  <p><strong>mode vs typeof:</strong> <a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/mode.html" rel="noreferrer">Very similar, except for a few differences</a>, most notably that both (typeof "integer" and "double") = (mode "numeric"); and both (typeof "special" and "builtin" = (mode "function").</p>
  
  <p><strong>class:</strong> Class is based on R's object-oriented class hierarchy. I'm having a hard time finding this graphically laid out, but the best I've been able to find is this diagram:</p>
  
  <p><a href="https://i.stack.imgur.com/bJR8r.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bJR8r.png" alt="rpy2 robjects package"></a></p>
  
  <p><em>(If anyone can point me to a more accurate R class hierarchy, I'll replace it.)</em></p>
  
  <p>Although the class names don't correspond exactly with the results of the R class() function, I believe the hierarchy is basically accurate. My understanding is that <strong>the "class" of an object--that is, the result of the class() function--is the root class in the hierarchy.</strong> So, for example, "Vector" is not a root class and so it never shows up as the result of the class() function. The root class might rather be "StrVector" ("character") or "BoolVector" ("logical"). In contrast, "Matrix" is itself a root class; hence, its class is "matrix".</p>
  
  <p>Apparently, R supports multiple inheritance, and so some objects can have more than one class.</p>
  
  <p><strong>typeof/mode/storage.mode vs class:</strong> This is what was hardest part for me to understand. My understanding now is this: typeof/mode/storage.mode (which I will refer to henceforth simply as <strong>"mode") is basically the most complex datatype that an R object can hold as one of its values</strong>. So, for example, since matrixes, arrays and vectors can hold only one vector datatype, their mode (that is, the most complex datatype they can hold) is typically numeric, character or logical, even though their class (their position in the class hierarchy) is something completely different.</p>
  
  <p>Where this gets most interesting (that is, confusing) is with objects like lists. A mode of "list" means that each value in the object can itself be a list (that is, an object that can hold diverse datatypes). Thus, regardless of if the class itself is "list", there are multiple objects (e.g. data frames) that can contain diverse values, and whose mode is therefore "list", even if their class is something else.</p>
  
  <p>So, in summary, my understanding is:</p>
  
  <ul>
  <li><p>typeof/mode/storage.mode (almost the same thing) is basically the most complex datatype that an R object can hold as one of its values; whereas</p></li>
  <li><p>class is an object's object-oriented classification according to the R class hierarchy.</p></li>
  </ul>
  
  <p><strong>Is my understanding accurate? If not, could someone please give a more accurate explanation?</strong></p>