title: “R Data Structures”

# create vectors of data for three medical patients
presidents_name <- c("Lindon Johnson", "George Bush", "John Kennedy")
president_salary <- c(200000, 400000, 175000)
application_status <- c(FALSE, FALSE, TRUE)
presidents_name[2]
## [1] "George Bush"
president_salary[2:3]
## [1] 400000 175000
government_expenditure <- factor(c("LOW", "MODERATE", "HIGH"),
                                  levels = c("LOW", "MODERATE", "HIGH"),
                                  ordered = TRUE)
government_expenditure >"MODERATE"
## [1] FALSE FALSE  TRUE
presidents_name[1]
## [1] "Lindon Johnson"
president_salary[1]
## [1] 2e+05
application_status[1]
## [1] FALSE
government_expenditure[1]
## [1] LOW
## Levels: LOW < MODERATE < HIGH
#creating list for president
president_term <- list(fullname = presidents_name[1], 
                 salary = president_salary[1],
                 application_status = application_status[1],
                 government_expenditure = government_expenditure[1])
president_term
## $fullname
## [1] "Lindon Johnson"
## 
## $salary
## [1] 2e+05
## 
## $application_status
## [1] FALSE
## 
## $government_expenditure
## [1] LOW
## Levels: LOW < MODERATE < HIGH
presidency_data <- data.frame(presidents_name, president_salary, application_status,
                              government_expenditure, stringsAsFactors = FALSE)
presidency_data
##   presidents_name president_salary application_status government_expenditure
## 1  Lindon Johnson           200000              FALSE                    LOW
## 2     George Bush           400000              FALSE               MODERATE
## 3    John Kennedy           175000               TRUE                   HIGH
presidency_data$presidents_name
## [1] "Lindon Johnson" "George Bush"    "John Kennedy"
presidency_data[c("presidents_name", "government_expenditure")]
##   presidents_name government_expenditure
## 1  Lindon Johnson                    LOW
## 2     George Bush               MODERATE
## 3    John Kennedy                   HIGH
presidency_data[2:3]
##   president_salary application_status
## 1           200000              FALSE
## 2           400000              FALSE
## 3           175000               TRUE
presidency_data[2,2]
## [1] 4e+05
presidency_data[c(2,1),c(3,1)]
##   application_status presidents_name
## 2              FALSE     George Bush
## 1              FALSE  Lindon Johnson
m1 <- matrix(c(1, 2, 3, 4), nrow = 2)
m1
##      [,1] [,2]
## [1,]    1    3
## [2,]    2    4
m2<-matrix(c(1,2,3,4),ncol = 2)
m2
##      [,1] [,2]
## [1,]    1    3
## [2,]    2    4
m1[1,1]
## [1] 1
m2[2,1]
## [1] 2
m3 <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2)
m3
##      [,1] [,2] [,3]
## [1,]    1    3    5
## [2,]    2    4    6
m4<-matrix(c(2,3,7,9,11,10),ncol = 2)
m4
##      [,1] [,2]
## [1,]    2    9
## [2,]    3   11
## [3,]    7   10
m4[1,]
## [1] 2 9
m4[,2]
## [1]  9 11 10