This lesson is in the early stages of development (Alpha version)

R datatypes

Overview

Teaching: 10 min
Exercises: 5 min
Questions
  • What types of data does the R language has?

Objectives
  • Learn the types of data that we can manage in R.

Types of data

We already used numbers to generate a result. But this is not the only type of data that RStudio can manage. We can use the command typeof() to corroborate the data type of our object addition:

> typeof(addition)
> [1] "double"

There are five types of data in RStudio:

> typeof(5L) #Integer type can contain only whole numbers followed by a capital L
[1] "integer"
> typeof(72+5i)
[1] "complex"
> addition == subtraction
[1] FALSE
> typeof(addition == subtraction)
[1] "logical"
> resultado <- "4 and 3 are not the same in Earth. In Mars maybe... "
> typeof(resultado)
[1] "character"

Also, we can use c() command to enlist a certain number of objects that we want to use. This can be accomplished by enlisting them inside the parenthesis, and separe each element by a comma. Let’s create a vector and found out its class:

> v.examp <- c("his ", "scabbard", "of", "chalcedony")
> typeof(v.examp)
[1] "character"

No matter how complicated our analysis can become, all data in R will be allocated as one of this five data types. On their own, data types are important because we want to know “who is who, and what is what”. But this concept will help us learn one of the most powerful tools in R, which is the manipulation of different types of data at the same time in a data-frame.

Key Points

  • R uses different types of data to store information.