B.4 Character Vectors

B.4.1 Creating Character Vectors

Individual character strings can be created using double quotes or apostrophes. These are the elements of character vectors

## [1] "a string"
## [1] "character"
## [1] "character"
## [1] 1
## [1] "aaa" "bb"  "c"   "aaa" "bb"  "c"

B.4.2 Concatenating Character Vectors

To join (concatenate) the corresponding elements of two or more character vectors, we call the paste() function:

## [1] "a 1" "b 2" "c 3"
## [1] "a1" "b2" "c3"

Also note:

## [1] "a 1" "b 2" "c 3"
## [1] "a 1" "b 2" "c 3" "a 4" "b 5" "c 6"
## [1] "a 1 !" "b 2 ?" "c 3 !" "a 4 ?" "b 5 !" "c 6 ?"

B.4.3 Collapsing Character Vectors

We can also collapse a sequence of strings to a single string:

## [1] "abcd"
## [1] "a,b,c,d"