An R Introduction to Statistics

Combining Vectors

Vectors can be combined via the function c. For examples, the following two vectors n and s are combined into a new vector containing elements from both vectors.

> n = c(2, 3, 5) 
> s = c("aa", "bb", "cc", "dd", "ee") 
> c(n, s) 
[1] "2"  "3"  "5"  "aa" "bb" "cc" "dd" "ee"

Value Coercion

In the code snippet above, notice how the numeric values are being coerced into character strings when the two vectors are combined. This is necessary so as to maintain the same primitive data type for members in the same vector.