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.


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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s