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" 
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s