[R] indexing a vector starting from 0

Sean Davis sdavis2 at mail.nih.gov
Sun Jul 24 22:38:20 CEST 2005

On Jul 24, 2005, at 4:29 PM, Federico Calboli wrote:

> Hi All,
> I would like to ask if it possible to start indexing a vector from 0:
> x = 1:10
> y = c(0,0,3,4,5,6,0,8,9,10)
> I need to use y as an index to extract the values of x, BUT I cannot
> cull/transform the 0s. What I would like is to start counting the
> elements of x 0:9 rather than 1:10. Would this be at all possible?

Is there a reason why you can't add 1 to the x indices, like:


Otherwise, you could use a list.


More information about the R-help mailing list