Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
What are vectors?
3. Creating a numeric vector using the colon operator
Vector operations
Indexing and filtering
Summary

Instruction

Cool! You can also create a vector by defining its elements with the colon (:) operator. The colon operator allows you to specify a range of numbers. For example, 1:5 generates the sequence of numbers 1, 2, 3, 4, 5, where each value in the sequence is one greater than the previous. So, instead of creating a vector this way:

id <- c(11, 12, 13, 14, 15)

You can alternatively use the following syntax:

id <- 11:15

Both lines of code will give the same exact result – numeric vector named id with elements 11, 12, 13, 14, and 15. However, the colon operator is more convenient if you need to define vectors with many elements, such as a sequence from 1 to 100 (1, 2, 3, ..., 99, 100).

Unfortunately, with the colon operator, you're strictly limited to sequences in which each subsequent element increases by one. If you want to create a different kind of sequence, you'll need to resort to using c().

Exercise

Versico has 12 employees. Each employee in Versico's database is uniquely identifiable by a six-digit number, ranging from 100001 to 100012. Create a vector named ids that contains 12 numbers representing all possible employee ids in the range specified above. Do not manually type in all possible values.

Stuck? Here's a hint!

You should assign the following expression to the ids vector:

100001:100012