[R] x[0]: Can '0' be made an allowed index in R?

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Tue Apr 23 16:56:40 CEST 2024


While I certainly think using negative indices to denote element exclusion is a cool feature, I think people wanting to use zero-based indexes probably are not planning to use that feature. Python uses negative numbers to index from the end, which is a completely different use of negative indexes with the exclusion feature that R users just happily ignore. It is only the possible surprise that exclusion doesn't work consistently that is relevant here.

I would hope that uses of alternate indexing schemes in most packages be wrapped inside functions as much as possible so that R users don't have to get dragged into this paradigm shift to make use of those algorithms.

On April ,
>> v
>[0,] [1,] [2,] [3,] [4,] [5,] [6,] [7,] [8,] [9,]
>   1    2    3    4    5    6    7    8    9   10
>
>> dim(v)
>[1] 10
>
>> v[-1]
>[1]  1  3  4  5  6  7  8  9 10
>
>> v[-0]
>[1] 1
>
>Best,
> John
>
>On 2024-04-23 9:03 a.m., Peter Dalgaard via R-help wrote:
>> Caution: External email.
>> 
>> 
>> Doesn't sound like you got the point. x[-1] normally removes the first element. With 0-based indices, this cannot work.
>> 
>> - pd
>> 
>>> On 22 Apr 2024, at 17:31 , Ebert,Timothy Aaron <tebert using ufl.edu> wrote:
>>> 
>>> You could have negative indices. There are two ways to do this.
>>> 1) provide a large offset.
>>> Offset <- 30
>>> for (i in -29 to 120) { print(df[i+Offset])}
>>> 
>>> 
>>> 2) use absolute values if all indices are negative.
>>> for (i in -200 to -1) {print(df[abs(i)])}
>>> 
>>> Tim
>>> 
>>> 
>>> 
>>> -----Original Message-----
>>> From: R-help <r-help-bounces using r-project.org> On Behalf Of Peter Dalgaard via R-help
>>> Sent: Monday, April 22, 2024 10:36 AM
>>> To: Rolf Turner <rolfturner using posteo.net>
>>> Cc: R help project <r-help using r-project.org>; Hans W <hwborchers using gmail.com>
>>> Subject: Re: [R] x[0]: Can '0' be made an allowed index in R?
>>> 
>>> [External Email]
>>> 
>>> Heh. Did anyone bring up negative indices yet?
>>> 
>>> -pd
>>> 
>>>> On 22 Apr 2024, at 10:46 , Rolf Turner <rolfturner using posteo.net> wrote:
>>>> 
>>>> 
>>>> See fortunes::fortune(36).
>>>> 
>>>> cheers,
>>>> 
>>>> Rolf Turner
>>>> 
>>>> --
>>>> Honorary Research Fellow
>>>> Department of Statistics
>>>> University of Auckland
>>>> Stats. Dep't. (secretaries) phone:
>>>>         +64-9-373-7599 ext. 89622
>>>> Home phone: +64-9-480-4619
>>>> 
>>>> ______________________________________________
>>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat/
>>>> .ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl.edu
>>>> %7C79ca6aadcaee4aa3241308dc62d986f6%7C0d4da0f84a314d76ace60a62331e1b84
>>>> %7C0%7C0%7C638493933686698527%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
>>>> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=
>>>> wmv9OYcMES0nElT9OAKTdjBk%2BB55bQ7BjxOuaVVkPg4%3D&reserved=0
>>>> PLEASE do read the posting guide
>>>> http://www.r/
>>>> -project.org%2Fposting-guide.html&data=05%7C02%7Ctebert%40ufl.edu%7C79
>>>> ca6aadcaee4aa3241308dc62d986f6%7C0d4da0f84a314d76ace60a62331e1b84%7C0%
>>>> 7C0%7C638493933686711061%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL
>>>> CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=AP78X
>>>> nfKrX6B0YVM0N76ty9v%2Fw%2BchHIytw33X7M9umE%3D&reserved=0
>>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> --
>>> Peter Dalgaard, Professor,
>>> Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>>> Phone: (+45)38153501
>>> Office: A 4.23
>>> Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com
>>> 
>>> ______________________________________________
>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>> 
>> --
>> Peter Dalgaard, Professor,
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Office: A 4.23
>> Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list