Ebert,Timothy Aaron
2024-Apr-22 15:31 UTC
[R] x[0]: Can '0' be made an allowed index in R?
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 at r-project.org> On Behalf Of Peter Dalgaard via R-help Sent: Monday, April 22, 2024 10:36 AM To: Rolf Turner <rolfturner at posteo.net> Cc: R help project <r-help at r-project.org>; Hans W <hwborchers at 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 at 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 at 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 at cbs.dk Priv: PDalgd at gmail.com ______________________________________________ R-help at 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.
Convert to character: goofy <- 1:9 names(goofy) <- (-4):4 goofy[as.character(0)] goofy["-2"] sg On 4/22/24 10:31 AM, Ebert,Timothy Aaron 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 at r-project.org> On Behalf Of Peter Dalgaard via R-help > Sent: Monday, April 22, 2024 10:36 AM > To: Rolf Turner <rolfturner at posteo.net> > Cc: R help project <r-help at r-project.org>; Hans W <hwborchers at 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 at 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 at 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 at cbs.dk Priv: PDalgd at gmail.com > > ______________________________________________ > R-help at 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 at 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.
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 at 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 at r-project.org> On Behalf Of Peter Dalgaard via R-help > Sent: Monday, April 22, 2024 10:36 AM > To: Rolf Turner <rolfturner at posteo.net> > Cc: R help project <r-help at r-project.org>; Hans W <hwborchers at 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 at 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 at 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 at cbs.dk Priv: PDalgd at gmail.com > > ______________________________________________ > R-help at 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 at 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 at cbs.dk Priv: PDalgd at gmail.com