Re: [R] index range

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 18 Feb 2008 19:01:01 -0500

On Feb 18, 2008 6:52 PM, Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote:
> You can define origin 0 objects yourself if you like.
> Here is a partial implementation:
>
> "[.orig0" <- function(x, i)

The 0 should be a 1.

> if (is.numeric(i)) .subset(x, i+0) else .subset(x, i)
> orig0 <- function(x)
> structure(x, class = c("orig0", setdiff(class(x), "orig0")))
> x <- orig0(1:5)
> x[0:3] # 1:4
>
> Note that usually 0 means leave out that element in R and
> in this implementation -1 means leave it out. Also normally
> -3 mean leave out 3rd element but in the implementation
> above -0 would be 0 so it would give the first element.
>
> Probably best to just get used to the R way.
>
>
> On Feb 18, 2008 6:31 PM, hill0093 <hill0093_at_umn.edu> wrote:
> >
> > It looks to me like the index range starts at 1 in R.
> > Is this true?
> > If so, is there a way to change it to start at 0?
> > That way, I wouldn't have to make so many
> > changes when I translate a function from
> > another language.
> > --
> > View this message in context: http://www.nabble.com/index-range-tp15550797p15550797.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > R-help_at_r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Feb 2008 - 00:03:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 01:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive