Chapter 2.1 Data Structures
Basic data types
R has several core data structures:
- Vectors
- Factors
- Lists
- Matrices/arrays
- Data frames
Vectors form the basis of R data structures. The most basic type of R object is a vector.
There are two main types - atomic and lists.
There is really only one rule about vectors in R, which is that A vector can only contain objects of the same class. All elements of an atomic vector are the same type.
But of course, like any good rule, there is an exception, which is a list, which we will get to a bit later.
A list is represented as a vector but can contain objects of different classes. Indeed, that’s usually why we use them.
R has five basic or “atomic” classes of objects:
- character
- numeric (double) (real numbers)
- integer
- logical (True/False)
- complex
Vectors of numeric (real) or complex values, vectors of logical values and vectors of character strings are all known as “atomic” structures since their components are all of the same type, or mode.
There is also a class for “raw” objects, but they are not commonly used directly in data analysis and I won’t cover them here.