An R Introduction to Statistics

Named Vector Members

We can assign names to vector members.

For example, the following variable v is a character string vector with two members.

> v = c("Mary", "Sue") 
> v 
[1] "Mary" "Sue"

We now name the first member as First, and the second as Last.

> names(v) = c("First", "Last") 
> v 
 First   Last 
"Mary"  "Sue"

Then we can retrieve the first member by its name.

> v["First"] 
[1] "Mary"

Furthermore, we can reverse the order with a character string index vector.

> v[c("Last", "First")] 
  Last  First 
 "Sue" "Mary"