 # Data Structures

## Vectors

Vectors are defined as a sequence of data elements of a certain data type. Below are 3 different types of vectors as examples

### Numeric Vectors

Num_Vec <- c(3,6,9)

` 3.2 6.0 9.0`

### Logical Vectors

Log_Vec <- c(“TRUE”, “TRUE”, “FALSE”)

` "TRUE"  "TRUE"  "FALSE"`

### Character Vectors

Char_Vec <- c(“Steve”, “Sarah”, “Tim”)

` "Steve" "Sarah" "Tim"  `

## Data Frames

A data frame is a named list of vectors where the length of each vector is must be the same.

df <- data.frame(Num_Vec, Log_Vec, Char_Vec)

``````##   Num_Vec Log_Vec Char_Vec
## 1       3    TRUE    Steve
## 2       6    TRUE    Sarah
## 3       9   FALSE      Tim``````

## List

A list is a vector of data structures

mylist <- list(Num = Num_Vec,
Logic = Log_Vec,
Char = Char_Vec)

``````## \$Num
##  3 6 9
##
## \$Logic
##  "TRUE"  "TRUE"  "FALSE"
##
## \$Char
##  "Steve" "Sarah" "Tim"``````

## Matrix

Matrix is two-dimensional data structures where all data types must be the same.

Below is an example of a matrix where we set the number of data elements to 20 where we have 5 columns each with 4 rows of data.

mat <- matrix(1:20, 4,5)

``````##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    5    9   13   17
## [2,]    2    6   10   14   18
## [3,]    3    7   11   15   19
## [4,]    4    8   12   16   20``````