R has two simple, yet very useful functions to easily create vectors that respect certain conditions. The operator “**:**” allows you to create vectors within a specified range. Thus:

1 |
vec <- 1:5 |

creates a vector with integers between 1 and 5 (inclusive). To create a sequence of even integers between 0 and 10, for example, you can use the seq() function as follows:

1 |
evenInts <- seq(0, 10, by=2) |

The *by* parameter is the count the function uses to determine the next number in the sequence. By default this is* 1*.

The rep() function is used to create vectors according to a repeated pattern. The following are some examples of the rep function:

1 2 3 |
rep(2, 8) # repeat 2 eight times rep(seq(0,10,by=2), 2) # repeat the sequence of even integers between 0 and 2 twice rep(c(1,24), c(8,2)) # repeat 1 for 3 times and 24 twice |

Hope that you find this tutorial useful!