What is the seq() function in R?
Overview
In R, the seq() function is used to generate a regular sequence of numbers.
Syntax
seq(from, to, by)
Parameter value
The seq() function takes three parameter values:
from: This represents where the sequence should begin.to: This represents where the sequence should end.by: This represents the step size or interval of the sequence.
Return value
The seq() function returns a regular sequence.
Code example
# using the seq() functioneven_numbers <- seq(from = 0, to = 10, by = 2)even_numbers
Code explanation
- Line 2: We use the
seq()function to generate a sequence of numbers, from0to10, with a step size or interval of2. We also assign the output of the sequence to a variable calledeven_numbers. - Line 4: We print the
even_numbersvariable.