How to increment the sequences by a fixed value in R

r

#1

I was studying about the sequencing in R while studying I faced a problem that how to increment the value
for example I want to create a sequence between 1 and 100 and value should increment by 2
so I am looking for answer 1 3 5 7 …


#2

If you search

?seq

in console, you will get the document with default values and the various arguments you can give as follows:

seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
    length.out = NULL, along.with = NULL, ...)

Thus, you can achieve the above by:

seq(1,100,by=2)

[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57
[30] 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

Hope this helps!