Re: [R] indexing a vector starting from 0

From: Sean Davis <sdavis2_at_mail.nih.gov>
Date: Mon 25 Jul 2005 - 06:38:20 EST

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:

x[y+1]

Otherwise, you could use a list.

Sean



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 25 06:45:29 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:00 EST