Re: [R] select elements in a list

From: arnaud Gaboury <arnaud.gaboury_at_gmail.com>
Date: Fri, 21 May 2010 11:43:59 +0200

TY Ivan

select <- l[which(l==x):which(l==y)] returns the correct result.

> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> project.org] On Behalf Of Ivan Calandra
> Sent: Friday, May 21, 2010 11:20 AM
> To: r-help_at_r-project.org
> Subject: Re: [R] select elements in a list
>
> Hi,
>
> This should work:
> select <- l[which(l==x):which(l==y)]
>
> The problem is that you tried to select the values, but gave x and y as
> indexes. That's why you didn't get the expected result.
>
> See ?which for more info.
>
> HTH,
> Ivan
>
> Le 5/21/2010 11:07, arnaud Gaboury a écrit :
> > Dear group,
> >
> > Here is a list :
> >
> > l<-
> > list("100415", "100416", "100419", "100420", "100421", "100422",
> > "100423", "100426", "100427", "100428", "100429", "100430",
> > "100503", "100504", "100505", "100506", "100507", "100510",
> > "100511", "100512", "100513")
> >
> > I need to access part of it with two variables, x and y. For example,
> if
> > x<-100415 et y<-100420, the result I want is
> 100415,100416,100419,100420.
> > The object "l" is a list, but can be of any other kind if it can
> help.
> >
> > I tried something like this :
> >
> >> select<-l[c(x:y)]
> >>
> > But it doesn't return the needed result
> >
> > Any help would be appreciated
> >
> > ***************************
> > Arnaud Gaboury
> > Mobile: +41 79 392 79 56
> > BBM: 255B488F
> >
> > ______________________________________________
> > 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.
> >
> >
>
> --
> Ivan CALANDRA
> PhD Student
> University of Hamburg
> Biozentrum Grindel und Zoologisches Museum
> Abt. Säugetiere
> Martin-Luther-King-Platz 3
> D-20146 Hamburg, GERMANY
> +49(0)40 42838 6231
> ivan.calandra_at_uni-hamburg.de
>
> **********
> http://www.for771.uni-bonn.de
> http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
>
> ______________________________________________
> 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 Fri 21 May 2010 - 09:48:00 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 Fri 21 May 2010 - 09:50:23 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