<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/understanding-data/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://tomhopper.me/2017/06/19/understanding-data-through-scales-of-measurement/"> RStats – Tom Hopper</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>When analyzing data, I have often found it useful to think of the data as being one of four main types, according to the typology proposed by Stevens.<sup>[<a rel="nofollow" href="https://tomhopper.me/2017/06/19/understanding-data-through-scales-of-measurement/#refStevens" target="_blank">1</a>]</sup> Different types of data have certain characteristics; understanding what type of data you have helps with selecting the analysis to perform and prevent basic analysis mistakes.</p>
<p>The types, or “scales of measurement,” are:</p>
<dl><a></a>
<dt>Nominal<a></a></dt>
<dd> Data identifying unique classifications or objects where the order of values is not meaningful. Examples include zip codes, gender, nationality, sports teams and multiple choice answers on a test.</dd>
<dt>Ordinal<a></a></dt>
<dd> Data where the order is important but the difference or distance between items is not important or not measured. Examples include team rankings in sport (team A is better than team B, but <em>how much better</em> is open to debate), scales such as health (e.g. “healthy” to “sick”), ranges of opinion (e.g. “strongly agree” to “strongly disagree” or “on a scale of 1 to 10”) and Intelligence Quotient.</dd>
<dt>Interval<a></a></dt>
<dd> Numeric data identified by values where the degree of difference between items is significant and meaningful, but their ratio is not. Common examples are dates—we can say 2000 CE is 1000CE + 1000 years, but 1000 CE is not half of 2000 CE in any meaningful way—and temperatures on the Celsius and Fahrenheit scales, where a difference of 10° is meaningful, but 10° is not twice as hot as 5°.</dd>
<dt>Ratio<a></a></dt>
<dd> Numeric data where the ratio between numbers is meaningful. Usually, such scales have a meaningful “0.” Examples include length, mass, velocity, acceleration, voltage, power, duration, energy and Kelvin-scale temperature.</dd>
</dl>
<p>The generally-appropriate statistics and mathematical operations for each type are summarized in table <a rel="nofollow" href="https://tomhopper.me/2017/06/19/understanding-data-through-scales-of-measurement/#tab_Scales_of_measurement" target="_blank">1</a>.</p>
<p><a></a></p>
<table>
<caption><a></a>Table 1: <a></a>Scales of measurement and allowed statistical and mathematical operations.</caption>
<tbody>
<tr>
<th align="left" valign="top"><a></a>Scale Type</th>
<th align="left" valign="top"><a></a>Statistics</th>
<th align="left" valign="top"><a></a>Operations</th>
</tr>
<tr>
<td align="left" valign="top"><a></a>Nominal</td>
<td align="left" valign="top"><a></a>mode, frequency, chi-squared, cluster analysis</td>
<td align="left" valign="top"><a></a>=, ≠</td>
</tr>
<tr>
<td align="left" valign="top"><a></a>Ordinal</td>
<td align="left" valign="top"><a></a>above, plus: median, non-parametric tests, Kruskal-Wallis, rank-correlation</td>
<td align="left" valign="top"><a></a>=, ≠, >, </td>
</tr>
<tr>
<td align="left" valign="top"><a></a>Interval</td>
<td align="left" valign="top"><a></a>plus: arithmetic mean, some parametric tests, correlation, regression, ANOVA (sometimes), factor analysis</td>
<td align="left" valign="top"><a></a>=, ≠, >, &lt;,+, –</td>
</tr>
<tr>
<td align="left" valign="top"><a></a>Ratio</td>
<td align="left" valign="top"><a></a>plus: geometric and harmonic mean, ANOVA, regression, correlation coefficient</td>
<td align="left" valign="top"><a></a>=, ≠, >, &lt;,+, -, ×, ÷</td>
</tr>
</tbody>
</table>
<p><a></a>While this is a useful typology for most use, and certainly for initial consideration, there are valid criticisms of Stevens’ typology. For example, percentages and count data have some characteristics of ratio-scale data, but with additional constraints. e.g. the average of the counts <img alt="overline{(2, 2, 1)} = 1.66ldots" title="overline{(2, 2, 1)} = 1.66ldots" src="https://s0.wp.com/latex.php?latex=%5Coverline%7B%282%2C+2%2C+1%29%7D+%3D+1.66%5Cldots&bg=ffffff&%23038;fg=808080&%23038;s=0" class="latex"> may not be meaningful. This typology is a useful thinking tool, but it is essential to understand the statistical methods being applied and their sensitivity to departures from underlying assumptions.</p>
<h3><a></a>Types of data in R</h3>
<p><a></a>R<sup>[<a rel="nofollow" href="https://tomhopper.me/2017/06/19/understanding-data-through-scales-of-measurement/#refRCore" target="_blank">2</a>]</sup> recognizes at least fifteen different types of data. Several of these are related to identifying functions and other objects—most users don’t need to worry about most of them. The main types that industrial engineers and scientists will need to use are:</p>
<dl><a></a>
<dt>numeric</dt>
<dd> <a></a>Real numbers. Also known as <em>double</em>, <em>real</em> and <em>single</em> (note that R stores all real numbers in double-precision). May be used for all scales of measurement, but is particularly suited to ratio scale measurements.</dd>
<dt>complex</dt>
<dd> <a></a>Imaginary<a></a> real numbers can be manipulated directly as a data type using 
<pre>x &lt;- 1 + i2</pre>
<p>
or </p>
<pre>x &lt;- complex(real=1, imaginary=2)</pre>
<p>
Like type <em>numeric</em>, may be used for all scales of measurement.
<dt>integer</dt>
<dd> <a></a>Stores integers only, without any decimal point. Can be used mainly for ordinal or interval data, but may be used as ratio data—such as counts—with some caution.</dd>
<dt>logical</dt>
<dd> <a></a>Stores Boolean values of TRUE or FALSE, typically used as nominal data.</dd>
<dt>character</dt>
<dd> <a></a>Stores text strings and can be used as nominal or ordinal data.</dd>

<h3><a></a>Types of variables in R</h3>
<p><a></a>The above types of data can be stored in several types, or structures, of variables. The equivalent to a variable in Excel would be rows, columns or tables of data. The main ones that we will use are:</p>
<dl><a></a>
<dt>vector</dt>
<dd> <a></a>Contains one or many elements, and behaves like a column or row of data. Vectors can contain any of the above types of data but each vector is stored, or <em>encoded</em>, as a single type. The vector
<pre>c(1, 2, 1, 3, 4)
## [1] 1 2 1 3 4</pre>
<p>	is, by default, a <em>numeric </em>vector of type <em>double</em>, but </p>
<pre>c(1, 2, 1, 3, 4, &quot;name&quot;)
## [1] &quot;1&quot; &quot;2&quot; &quot;1&quot; &quot;3&quot; &quot;4&quot; &quot;name&quot;</pre>
<p>	will be a <em>character vector</em>, or a vector where all data is stored as type <em>character</em>, and the numbers will be stored as characters rather than numbers. It will not be possible to perform mathematical operations on these numbers-stored-as-characters without first converting them to type numeric.
<dt>factor</dt>
<dd><a></a>A special type of character vector, where the text strings signify factor levels and are encoded internally as integer counts of the occurrence of each factor. Factors can be treated as nominal data when the order does not matter, or as ordinal data when the order does matter.</dd>
<pre>factor(c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;a&quot;), levels=c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;))
## [1] a b c a  
## Levels: a b c d</pre>
<dt>array</dt>
<dd> <a></a>A generalization of vectors from one dimension to two or more dimensions. Array dimensions must be pre-defined and can have any number of dimensions. Like vectors, all elements of an array must be of the same data type. (Note that the <em>letters</em> object used in the example below is a variable supplied by R that contains the letters <em>a</em> through <em>z</em>.)<a></a>
<pre># letters a - c in 2x4 array 
array(data=letters[1:3], dim=c(2,4))
##      [,1] [,2] [,3] [,4]  
## [1,] &quot;a&quot;  &quot;c&quot;  &quot;b&quot;  &quot;a&quot;  
## [2,] &quot;b&quot;  &quot;a&quot;  &quot;c&quot;  &quot;b&quot;

# numbers 1 - 3 in 2x4 array 
array(data=1:3, dim=c(2,4))
##      [,1] [,2] [,3] [,4]  
## [1,]    1    3    2    1  
## [2,]    2    1    3    2</pre>
</dd>
<dt>matrix</dt>
<dd> <a></a>A special type of array with the properties of a mathematical matrix. It may only be two-dimensional, having rows and columns, where all columns must have the same type of data and every column must have the same number of rows. R provides several functions specific to manipulating matrices, such as taking the transpose, performing matrix multiplication and calculation eigenvectors and eigenvalues.
<pre>matrix(data = rep(1:3, times=2), nrow=2, ncol=3)
##      [,1] [,2] [,3]  
## [1,]    1    3    2  
## [2,]    2    1    3</pre>
</dd>
<dt>list</dt>
<dd> <a></a>Vectors whose elements are other R objects, where each object of the list can be of a different data type, and each object can be of different length and dimension than the other objects. Lists can therefore store all other data types, including other lists.
<pre>list(&quot;text&quot;, &quot;more&quot;, 2, c(1,2,3,2))
## [[1]]  
## [1] &quot;text&quot;  
##  
## [[2]]  
## [1] &quot;more&quot;  
##  
## [[3]]  
## [1] 2  
##  
## [[4]]  
## [1] 1 2 3 2</pre>
</dd>
<dt>data.frame</dt>
<dd> <a></a>For most industrial and data scientists, data frames are the most widely useful type of variable. A data.frame is the <em>list</em> analog to the <em>matrix</em>: it is an <img alt="m times n" title="m times n" src="https://s0.wp.com/latex.php?latex=m+%5Ctimes+n&bg=ffffff&%23038;fg=808080&%23038;s=0" class="latex"> list where all columns must be vectors of the same number of rows (determined with <tt>NROW()</tt>). However, unlike matrices, different columns can contain different types of data and each row and column <em>must</em> have a name. If not named explicitly, R names rows by their row number and columns according to the data assigned assigned to the column. Data frames are typically used to store the sort of data that industrial engineers and scientists most often work with, and is the closest analog in R to an Excel spreadsheet. Usually data frames are made up of one or more columns of factors and one or more columns of numeric data.
<pre>data.frame(rnorm(5), rnorm(5), rnorm(5))
##     rnorm.5.  rnorm.5..1  rnorm.5..2  
## 1  0.2939566  1.28985202 -0.01669957  
## 2  0.3672161 -0.01663912 -1.02064116  
## 3  1.0871615  1.13855476  0.78573775  
## 4 -0.8501263 -0.17928722  1.03848796  
## 5 -1.6409403 -0.34025455 -0.62113545</pre>
</dd>

<p><a></a>More generally, in R all variables are <em>objects</em>, and R distinguishes between objects by their internal storage type and by their class declaration, which are accessible via the <tt>typeof()</tt><a></a> and <tt>class()</tt><a></a> functions. Functions in R are also objects, and the users can define new objects to control the output from functions like <tt>summary()</tt><a></a> and <tt>print()</tt><a></a>. <a></a>For more on objects, types and classes, see section 2 of the <a rel="nofollow" href="https://cran.r-project.org/doc/manuals/R-lang.html#Objects" target="_blank"><em>R Language Definition</em></a>.</p>
<p><a></a>Table <a rel="nofollow" href="https://tomhopper.me/2017/06/19/understanding-data-through-scales-of-measurement/#tab_var_type_table" target="_blank">2</a> summarizes the internal storage and R classes of the main data and variable types. </p>
<table cellspacing="0" cellpadding="0">
<caption>Table 2: <a></a>Table of R data and variable types.</caption>
<tbody>
<tr>
<th>Variable type</th>
<th>Storage type</th>
<th>Class</th>
<th>Measurement Scale</th>
</tr>
<tr>
<td>vector of decimals </td>
<td>double </td>
<td>numeric </td>
<td>ratio </td>
</tr>
<tr>
<td>vector of integers </td>
<td>integer </td>
<td>integer </td>
<td>ratio or interval</td>
</tr>
<tr>
<td>vector of complex </td>
<td>complex </td>
<td>complex </td>
<td>ratio </td>
</tr>
<tr>
<td>vector of characters </td>
<td>character </td>
<td>character </td>
<td>nominal </td>
</tr>
<tr>
<td>factor vector </td>
<td>integer </td>
<td>factor </td>
<td>nominal or ordinal </td>
</tr>
<tr>
<td>matrix of decimals </td>
<td>double </td>
<td>matrix </td>
<td>ratio </td>
</tr>
<tr>
<td>data frame </td>
<td>list </td>
<td>data.frame </td>
<td>mixed </td>
</tr>
<tr>
<td>list </td>
<td>list </td>
<td>list </td>
<td>mixed </td>
</tr>
</tbody>
</table>
<h3>References</h3>
<ol>
<li><a name="refStevens"></a>Stevens, S. S. “On the Theory of Scales of Measurement.” Science. 103.2684 (1946): 677-680. Print.</li>
<li><a name="refRCore"></a>R Core Team (2017). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL <a rel="nofollow" href="https://www.r-project.org/" target="_blank">https://www.R-project.org/</a>.</li>
</ol>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomhopper.wordpress.com/1337/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/tomhopper.wordpress.com/1337/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://tomhopper.me/2017/06/19/understanding-data-through-scales-of-measurement/"> RStats – Tom Hopper</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/SSx2jCyD4W4" height="1"></a></div></dd></dl></dd></dl>