2.4 Vectors
A sequence of values of the same type (e.g. numeric or character).
If you include multiple types, R will automatically force same type.
# Spahn's wins and losses after the war (this is a code comment)
W <- c(8, 21, 15, 21, 21, 22, 14)
L <- c(5, 10, 12, 14, 17, 14, 19)
win_pct <- 100 * W / (W + L)
Year <- seq(from = 1946, to = 1952) # Same: Year <- 1946:1952
R has a lot of built-in functions for vectors
## [1] 122
## [1] 7
## [1] 57.66207
Ways to select data with vector index and logicals.
## [1] 8 21 21
## [1] 8 21 15 21
## [1] 21 15 21 21 14
How many times did Spahn exceed 20 wins? What years?
## [1] FALSE TRUE FALSE TRUE TRUE TRUE FALSE
## [1] 4
## [1] 1947 1949 1950 1951