3 Vectors
3.1 Creating a vector
<- c(-1,0,1,2,3,4)
vet1 vet1
## [1] -1 0 1 2 3 4
or
<- -1:4
vet2 vet2
## [1] -1 0 1 2 3 4
It is possible to create vectors with characters
<- c("AU", "TH", "Test - 1", "Test = 0")
vetc vetc
## [1] "AU" "TH" "Test - 1" "Test = 0"
3.3 Accessing vector elements
Only the element in position 2
2] vet2[
## [1] 0
Different positions in the same vector
c(1,3,4)] vet2[
## [1] -1 1 2
3.4 Indexing vectors with characters
<- c("One" = 0, "Two" = 3, "Three" = 5)
vet vet
## One Two Three
## 0 3 5
"Two"] vet[
## Two
## 3
OR
<- c(0,3,5)
vet names(vet) <- c("One","Two","Three")
vet
## One Two Three
## 0 3 5
"Two"] vet[
## Two
## 3