How do I generate a list with a specified increment step?

r seq
LostLin picture LostLin · Sep 7, 2011 · Viewed 146.8k times · Source

How do I generate a vector with a specified increment step (e.g. 2)? For example, how do I produce the following

0  2  4  6  8  10

Answer

John picture John · Sep 7, 2011

Executing seq(1, 10, 1) does what 1:10 does. You can change the last parameter of seq, i.e. by, to be the step of whatever size you like.

> #a vector of even numbers
> seq(0, 10, by=2) # Explicitly specifying "by" only to increase readability 
> [1]  0  2  4  6  8 10