Chapter 8 Changing Variable Type

8.1 Intro

The data series that represent measurements or variables generally have metadata specifying their ‘data type’, ‘measure type’, or ‘class’. These types entail certain restrictions regarding what can be stored in each data point. For example, data series where the data points have the ‘text’ or ‘string’ data type have no restrictions (and as a consequence, cannot be used to perform computations); ‘numeric’ or ‘scale’ data series can only contain numbers (and allow computations); ‘factor’ data series contain categorical data; and ‘datetime’ or ‘date’ dataseries contain dates and times. This chapter explains how to change the type of a column in a dataset.

8.1.1 Example dataset

This example uses the Rosetta Stats example dataset “pp15” (see Chapter 1 for information about the datasets and Chapter 3 for an explanation of how to load datasets).

8.1.2 Variable(s)

Here, explain which variable(s) people should open to copy the examples. For example:

From this dataset, this example uses the following variables:

  • As a numeric variable: weight_other
  • As a binary variable: hadJob_bi
  • As a variable stored as numeric but that may also be considered categorical: highDose_IntentionRAA_intention

8.2 Input: jamovi

In jamovi, there’s a very general data type that’s called ‘nominal’. That doesn’t mean that it represents a measurement at the ‘nominal level of measurement’; instead, it is a sort of general-purpose data type.

To change a variable’s data type in jamovi, click the ‘Data’ tab at the top and select the column of the relevant variable. Then, you can specify the data type using two dropbox boxes: one labelled ‘Measure type’, which determines how the variable is treated in jamovi, and one labelled ‘Daat type’ which relates to the way the variable is stored in the dataset. By setting ‘Measure type’ to nominal, as shown in Figure 8.1, a variable can be used in most analyses.

A screenshot placeholder

Figure 8.1: A screenshot placeholder

8.3 Input: R

In R, columns in a data frame can have the following frequently used data types:

  • logical, which can only have TRUE and FALSE as values;
  • numeric, which can only have numbers as values;
  • character, which can handle literal text strings;
  • factor, which can handle categorical data.

To convert a column from one data type to another, the corresponding as.X can be used, where X is the new data type (so as.logical(), as.numeric(), as.character(), and as.factor().

8.4 Input: SPSS

For SPSS, there are two approaches: using the Graphical User Interface (GUI) or specify an analysis script, which in SPSS are called “syntax”.

8.4.1 SPSS: GUI

A screenshot placeholder

Figure 8.2: A screenshot placeholder

8.4.2 SPSS: Syntax

A screenshot placeholder

Figure 8.3: A screenshot placeholder

8.5 Output: jamovi

A screenshot placeholder

Figure 8.4: A screenshot placeholder

8.6 Output: R

A screenshot placeholder

Figure 8.5: A screenshot placeholder

8.7 Output: SPSS

A screenshot placeholder

Figure 8.6: A screenshot placeholder

8.8 Read more

Here, you can list one or more sources with background reading, for example:

If you would like more background on this topic, you can read more in these sources:


Navarro, Danielle. 2018. Learning Statistics with R. 0.6 ed. New South Wales, Australia.