View Full Version : c(2:10) increase by 2 (5 elements)


consuli
01-26-2010, 03:15 PM
Hello!

I am just starting with R and I know this is stupid question. But it is not in the R maunal and neither in my programming book.

I want create the vector x=[2, 4, 6, 8, 10]

with
x = c(2:10 by 2).

I know the option by is not correct, but what to type instead?

Thanks
Consuli

Mike White
01-26-2010, 04:21 PM
You can use the seq function
x<-seq(from=2, to=10,by=2)
x
#[1] 2 4 6 8 10
Type ?seq for more details of this function.

or

x<-2*(1:5)
x
#[1] 2 4 6 8 10