Chapter 8 Changing Variable Type
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
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:
- As a binary variable:
- As a variable stored as numeric but that may also be considered categorical:
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.
8.3 Input: R
In R, columns in a data frame can have the following frequently used data types:
logical, which can only have
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
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
8.4.2 SPSS: Syntax
8.5 Output: jamovi
8.6 Output: R
8.7 Output: SPSS
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: