2+2
## [1] 4

Vectors

We can simply consider a vector to be an ordered sequence of values of the same data type. A sequence is ordered such that the two sequences represented below are treated as two different entities by R:

Vectors

Vectors

c(100,20,40,15,90)
## [1] 100  20  40  15  90
vector <- c(100,20,40,15,90)
Type Example
numeric c(1,2,3)
logical/Boolean c(TRUE,FALSE,T,F)
character c(“A”,“a”,“Apple”)

Lists

Lists are a convenient way to store objects within the R environment: containers of objects.

## [[1]]
## [1] "List are containers of objects "                                     
## [2] " They are a convenient way to store objects within the R environment"
mode(x = tokenization_results)
## [1] "list"

Creating lists

first_vector  <- c("a","b","c")
second_vector <- c(1,2,3)
vector_list   <- list(first_vector, second_vector)
vector_list
## [[1]]
## [1] "a" "b" "c"
## 
## [[2]]
## [1] 1 2 3
mode(x=vector_list)
## [1] "list"

Subsetting lists

vector_list[[1]]
## [1] "a" "b" "c"
vector_list[[2]][[3]]
## [1] 3

Data frames

Data frames can be seen simply as lists respecting the following requisites:

  1. All components are vectors, no matter whether logical, numerical, or character
  2. All vectors must be of the same length
Data frames

Data frames

library(tidyverse)
a_data_frame <- tibble(first_attribute = c("alpha","beta","gamma"), second_attribute = c(14,20,11))
a_data_frame
## # A tibble: 3 x 2
##   first_attribute second_attribute
##   <chr>                      <dbl>
## 1 alpha                         14
## 2 beta                          20
## 3 gamma                         11
tibble(c("alpha","beta","gamma"), c(14,20,11))
## # A tibble: 3 x 2
##   `c("alpha", "beta", "gamma")` `c(14, 20, 11)`
##   <chr>                                   <dbl>
## 1 alpha                                      14
## 2 beta                                       20
## 3 gamma                                      11

Select and show a column of a data frame

a_data_frame$second_attribute
## [1] 14 20 11

Add a new column

a_data_frame$third_attribute <- c(TRUE,FALSE,FALSE)
a_data_frame
## # A tibble: 3 x 3
##   first_attribute second_attribute third_attribute
##   <chr>                      <dbl> <lgl>          
## 1 alpha                         14 TRUE           
## 2 beta                          20 FALSE          
## 3 gamma                         11 FALSE