# 6 A few important details

## 6.1 A primer on technicals

- R is CaSe-SeNsItIvE, e.g., “Gender” is different than “gender”
- Missing values are coded as NA (i.e., not available)

### 6.1.1 Variable types

**character**- Strings**integer**- Integers**numeric**- Integers + Rational + Irrational**factor**- Categorical variable where each level is a category**logical**- Boolean**complex**- Complex numbers

### 6.1.2 Data types

**vector**- A collection of elements of same class**matrix**- All columns must uniformly contain only one variable type.**data.frame**- The columns can contain different classes.**list**- Can hold objects of different classes and lengths

### 6.1.3 Classification of R Objects

This is important to learn and distinguish because in programming in R, you need to know the characteristics of the object you want to manipulate.

### 6.1.4 mode

There are five **main** types (technically “modes”) of R objects

**integer & numeric**: used for quantitative data. Our vector \(height\) is numeric.**character**: used for qualitative data. When there is one string like “Hey There Mate” or a website address.**logical**: TRUE or FALSE**list**: special R object ()**function**: sets of instructions contained in a sub program: e.g., mean()

try to find out the mode of the `height`

vector we created using the R function `mode()`

`## [1] "numeric"`

The mode of the R function \(mean()\) is ?

`## [1] "function"`

**In depth knowledge:** ‘mode’, is a mutually exclusive classification of objects according to their basic structure. An object has one and only one mode. The ‘atomic’ modes are numeric, complex, character and logical. Recursive objects have modes such as ‘list’ or ‘function’ or a few others. The emphasis on **“main”** was given as there are also other types of storage modes (such as raw, complex and others) but we are not going to use them in this course - for more info check \(?mode\).

### 6.1.5 class

Here are some of common R classes

- integer & numeric
- character & factor
- matrix (2D)
- list & data.frame

**In depth knowledge:** ‘class’ is a property assigned to an object that determines how generic functions operate with it. It is not a mutually exclusive classification. If an object has no specific class assigned to it, such as a simple numeric vector, it’s class is usually the same as its mode, by convention. For more info check \(?class\).

```
```
x <- 1 ; c(class(x), mode(x))
x <- letters ; c(class(x), mode(x)) # creates letters from a to z
x <- TRUE ; c(class(x), mode(x)) # logical
x <- cars ; c(class(x), mode(x)) # cars is probably the most famous dataset in R
x <- cars[1] ; c(class(x), mode(x)) # first collumn of cars dataset
x <- cars[[1]] ; c(class(x), mode(x)) # unlist the observations of the first collumn
x <- matrix(cars) ; c(class(x), mode(x)) # coerces cars into a matrix
x <- expression(1+1) ; c(class(x), mode(x)) # calculates the mathematical expression
x <- quote(y <- 1) ; c(class(x), mode(x)) # simply returns its argument, which is not evaluated
x <- mean ; c(class(x), mode(x)) #
```
```

```
x <- 1 ; c(class(x), mode(x))
x <- letters ; c(class(x), mode(x)) # creates letters from a to z
x <- TRUE ; c(class(x), mode(x)) # logical
x <- cars ; c(class(x), mode(x)) # cars is probably the most famous dataset in R
x <- cars[1] ; c(class(x), mode(x)) # first collumn of cars dataset
x <- cars[[1]] ; c(class(x), mode(x)) # unlist the observations of the first collumn
x <- matrix(cars) ; c(class(x), mode(x)) # coerces cars into a matrix
x <- expression(1+1) ; c(class(x), mode(x)) # calculates the mathematical expression
x <- quote(y <- 1) ; c(class(x), mode(x)) # simply returns its argument, which is not evaluated
x <- mean ; c(class(x), mode(x)) #
```

**In-depth knowledge:** Optional read & info

There is an excellent discussion on the difference between mode, class, and other characteristics of R objects such as storage.mode and type of here.