Values and Vectors
Indexing
Picking Positions
R indexes vectors starting at 1. Bracket indexing and helper functions select the pieces a script needs.
Program
Play the script to see the first and last city selected from one vector.
indexing.R
cities <- c("Paris", "Lima", "Cairo")
first <- cities[1]
last <- tail(cities, 1)
label <- paste(first, "to", last)
cat(label, "\n", sep = "")
one-based index
`cities[1]` selects the first element, not the zeroth.
tail
`tail(cities, 1)` selects the final element.
character vector
A character vector stores text values in order.