seq(): Sequence function

The function seq is a widely used function to generate a sequence. from, to, by, and length.out are widely used arguments in seq function.

The basic usage of seq function is written in the exercise.

Instruction

  • Click the Submit button.
  • See what happens in the console to generate even numbers within 1 to 100
# Generate a sequence from 1 to 10 by using seq function seq(from = 1, to = 10) seq(1, 10) seq(10) # Alternative way to make 1 to 10 sequence 1:10 # Generate a sequence of odd numbers from 1 to 100 by using seq function seq(from = 1, to = 100, by = 2) seq(1, 100, 2) # Generate a sequence of even numbers within 1 to 100 by using seq function seq(1, 100, 2) + 1 seq(2, 100, 2) 2 * seq(1, 50)

Previous: 1-10 | c(): combine values into a vector or a list

Next: 1-12 | rep(): replicate elements of vectors and lists

Back to Main