R structure

Here a brief introduction to data types, data structures and object oriented systems in R




## Installing package into 'C:/Users/gabri/OneDrive/Documentos/R/win-library/3.6'
## (as 'lib' is unspecified)

Good resources: https://adv-r.hadley.nz/foundations-intro.html

Data structures

Almost all other objects are built upon these foundations.

Dimension Homogeneous Heterogeneous
1d Atomic vector List
2d Matrix Data frame
nd Array

Vectors

Atomic vectors

There are four common types of atomic vectors that I’ll discuss in detail: logical, integer, double (often called numeric), and character

Atomic vectors are usually created with c(), short for combine.

Coercion

All elements of an atomic vector must be the same type, so when you attempt to combine different types they will be coerced to the most flexible type. Types from least to most flexible are: logical, integer, double, and character.

Lists

Lists are different from atomic vectors because their elements can be of any type, including lists. You construct lists by using list() instead of c()

## List of 4
##  $ : int [1:3] 1 2 3
##  $ : chr "a"
##  $ : logi [1:3] TRUE FALSE TRUE
##  $ : num [1:2] 2.3 5.9

Matrices and arrays

Adding a dim attribute to an atomic vector allows it to behave like a multi-dimensional array. A special case of the array is the matrix, which has two dimensions. Matrices are used commonly as part of the mathematical machinery of statistics.

Data frames

A data frame is the most common way of storing data in R,

A data frame is a list of equal-length vectors. This makes it a 2-dimensional structure, so it shares properties of both the matrix and the list.

data frames allocates more space than matrices

## 232 bytes
## 864 bytes

Base types

Underlying every R object is a C structure (or struct) that describes how that object is stored in memory. The struct includes the contents of the object, the information needed for memory management, and, most importantly for this section, a type. This is the base type of an R object.

S3

S3 is a very casual system. It has no formal definition of classes.

S4

works similarly to S3, but is more formal. There are two major differences to S3. S4 has formal class definitions, which describe the representation and inheritance for each class, and has special helper functions for defining generics and methods.

base types

There’s also one other system that’s not quite OO, but it’s important to mention here. The internal C-level types that underlie the other OO systems. Base types are mostly manipulated using C code, but they’re important to know about because they provide the building blocks for the other OO systems.

gabriel

18/11/2019