Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In R every "object" has a <code>mode</code> and a <code>class</code>. The former represents how an object is stored in memory (numeric, character, list and function) while the later represents its abstract type. For example:</p> <pre><code>d &lt;- data.frame(V1=c(1,2)) class(d) # [1] "data.frame" mode(d) # [1] "list" typeof(d) # list </code></pre> <p>As you can see data frames are stored in memory as <code>list</code> but they are wrapped into <code>data.frame</code> objects. The latter allows for usage of member functions as well as overloading functions such as <code>print</code> with a custom behavior. </p> <p><code>typeof</code>(<code>storage.mode</code>) will usually give the same information as <code>mode</code> but not always. Case in point:</p> <pre><code>typeof(c(1,2)) # [1] "double" mode(c(1,2)) # [1] "numeric" </code></pre> <p>The reasoning behind this can be found <a href="http://stat.ethz.ch/R-manual/R-devel/doc/manual/R-lang.html#Objects">here</a>:</p> <blockquote> <p>The R specific function <strong>typeof</strong> returns the type of an R object</p> <p>Function <strong>mode</strong> gives information about the mode of an object in the sense of Becker, Chambers &amp; Wilks (1988), and is more compatible with other implementations of the S language</p> </blockquote> <p>The link that I posted above also contains a list of all native R <code>basic types</code> (vectors, lists etc.) and all <code>compound objects</code> (factors and data.frames) as well as some examples of how <code>mode</code>, <code>typeof</code> and <code>class</code> are related for each type.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload