# Mastering Seq and Rep in R

The programming language R is commonly used in statistical modeling. Rep and seq functions are two of R’s basic functions. At first, the power may not be evident but when they are combined with other functions the power starts to manifest itself. These functions can easily be turned into helpful statistical tools.

## Rep in R

Rep has the format of rep(value,#repeats), and it repeats the value the number of times indicated. The simplest example of this function is a number repeated a specific number of times. Here is a rep in r example:

``````# rep in R example
> rep(1,5)
 1 1 1 1 1``````

This can also be done with characters.

``````# rep in R example
> rep("Bob",5)
 "Bob" "Bob" "Bob" "Bob" "Bob"``````

Any value, function, or variable placed into the value of rep in r will get duplicated the specified number of times. This makes the rep function useful for producing loops the need to be repeated a certain number of times. It is how to repeat a sequence in r.

## Seq in R

The seg function has the format of seq(from = value1, to = value2, by = step), and it creates a list of numbers between value1 to value2 with increments of step Here is an example:

``````# seq in R example
> seq(from = 0, to = 15, by = 3)
  0  3  6  9 12 15``````

It can also produce more complex sequences.

``````# seq in R example
> seq(from = 1.5, to = 15, by = 3.3)
  1.5  4.8  8.1 11.4 14.7``````

The seq function generates sequences of numbers that can be combined with other functions increasing the power of this relatively simple tool.

## Combinations

The real power of these functions comes from combining them with variables, other functions and each other. This ability to be combined is why they are such basic functions to the R language. When they are put together in various ways with variables and other functions making charts and graphs for data becomes quite easy. The result is that such combinations of these two functions with variables open the door various ways of presenting data in an easy to understand way. This ability is one of the reasons that R is used as in statistical modeling.

## Applications

Because rep in r repeats the value given to it, it provides a way on how to repeat a sequence in r. One rep in r example is making a data graph. One such application would be a star rating graph. For the seq function, it can be combined with other data make charts that through the cbind function are automatically formatted

The Rep and Seq functions in R are useful basic functions that helped make the R programming language an excellent statistical tool. Working together in conjunction with other functions and variables has applications for producing and formatting data. The results from these functions can be used to produce and display data in a simple step.

Scroll to top