4 Vectors
4.1 Creating a vector
vet1 <- c(-1,0,1,2,3,4)
vet1
## [1] -1 0 1 2 3 4or
vet2 <- -1:4
vet2
## [1] -1 0 1 2 3 4It is possible to create vectors with characters
vetc <- c("AU", "TH", "Test - 1", "Test = 0")
vetc
## [1] "AU" "TH" "Test - 1" "Test = 0"4.3 Accessing vector elements
Only the element in position 2
vet2[2]
## [1] 0Different positions in the same vector
vet2[c(1,3,4)]
## [1] -1 1 24.4 Indexing vectors with characters
vet <- c("One" = 0, "Two" = 3, "Three" = 5)
vet
## One Two Three
## 0 3 5vet["Two"]
## Two
## 3OR
vet <- c(0,3,5)
names(vet) <- c("One","Two","Three")
vet
## One Two Three
## 0 3 5vet["Two"]
## Two
## 34.6 Arithmetic operations
4.6.1 Operations with a constant
vet1 + 2
## [1] 1 2 3 4 5 6vet1 - 2
## [1] -3 -2 -1 0 1 2vet1 / 2
## [1] -0.5 0.0 0.5 1.0 1.5 2.0vet1 * 2
## [1] -2 0 2 4 6 8