Data Types

We have already learned that we can perform calculations directly in R or store the result directly in an object.

However, we can also directly store values in objects, distinguishing four different data types:

  1. numeric

  2. integer

  3. character

  4. logical

Numeric

This data type includes all possible numerical values. Strictly speaking, integer is a subtype of this numerical value. Therefore, we can also store decimal values in R. Let’s store a simple decimal number in the new object mathNum and then call it.

mathNum <- 2.345

mathNum
## [1] 2.345

Important for handling in the learning module: You can directly copy the code and paste it into your own script. In the top right corner of each code snippet, there is a copy symbol. Simply click on it and then paste it into your script (cmd and V or Ctrl and V).

What do you notice about entering the decimal number?

Integer

We already know this data type, as we used it in the math object. Integer are whole number values, like the value 7 in the math example.

Character

Next, we have the data type character. These are character strings: they can be meaningful words made up of letters, or combinations of letters and numbers or symbols. For example, let’s store an object hometown with the place of residence (in my case, Berlin).

hometown <- "Berlin"

hometown
## [1] "Berlin"
What do you notice as a difference when storing a numeric or integer value compared to storing text of type character?

logical

This data type plays an important role in data processing, as we will later use conditions that each have the data type logical. There are two possible values for the logical data type: TRUE and FALSE. Important: These words must be capitalized! Otherwise, R will not recognize them as logical. For example, let’s store the value TRUE in an object named truth.

truth <- TRUE

truth
## [1] TRUE

But can we store more than one value?