Populate a vector with incremental character values in R

The following code allows you to create a vector whose elements consist of character values numbered according to some range of values.

ID <- as.vector(paste("ID",as.character(1:5),sep=" "))

Note that there is a space between the quotation marks following the sep option.

Output

> ID
 [1] "ID 1"  "ID 2"  "ID 3"  "ID 4"  "ID 5" 

Leave a comment