[R] Selecting first 7 elements
Kang Min
ngokangmin at gmail.com
Mon May 31 01:22:13 CEST 2010
Sorry I made a mistake in my code, lapply(x, "[", 8:14) works fine
now. Thanks.
On May 30, 10:55 pm, Jorge Ivan Velez <jorgeivanve... at gmail.com>
wrote:
> HiKang,
>
> Try either
>
> lapply(x, "[", 8:14) # Erik Iverson's method
>
> or
>
> lapply(x, function(x) x[8:14])
>
> HTH,
> Jorge
>
>
>
>
>
> On Sun, May 30, 2010 at 9:44 AM,KangMin<> wrote:
> > Hmm x[8:14] didn't work. Yes Iverson's method worked, I wanted the
> > whole list, with 7 elements in each vector.
>
> > Now I want the whole list as well, but with the 8th to 14th element.
>
> > On May 30, 7:47 pm, David Winsemius <dwinsem... at comcast.net> wrote:
> > > On May 29, 2010, at 11:37 PM,KangMinwrote:
>
> > > > What if I want to select the 8th to 14th element of the list? I tried
> > > > to use "[" again, but it doesn't work.
>
> > > x[8:14]
>
> > > (And I could not get Iverson's earlier method to work properly on a
> > > long list. It just returned the whole list. Did it work properly for
> > > you? )
>
> > > --
> > > David.
>
> > > >>>> "[" is a function, and you want to use it on each element of the
> > > >>>> list,
> > > >>>> so...
>
> > > >>>> lapply(x, "[", c(1:7))
>
> > > >>> and the call to c() is of course not necessary, since ":" will
> > > >>> generate a vector.
>
> > > >>> ______________________________________________
> > > >>> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/
> > > >>> listinfo/r-help
> > > >>> PLEASE do read the posting guidehttp://
> >www.R-project.org/posting-guide.html
> > > >>> and provide commented, minimal, self-contained, reproducible code.
>
> > > >>> --
> > > >>> You received this message because you are subscribed to the Google
> > > >>> Groups "R-help-archive" group.
> > > >>> To post to this group, send email to r-help-
> > > >>> archive at googlegroups.com.
> > > >>> To unsubscribe from this group, send email to
> > r-help-archive+unsubscribe at googlegroups.com<r-help-archive%2Bunsubscribe at go oglegroups.com>
> > > >>> .
> > > >>> For more options, visit this group athttp://
> > groups.google.com/group/r-help-archive?hl=en
> > > >>> .
>
> > > >> ______________________________________________
> > > >> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/
> > > >> listinfo/r-help
> > > >> PLEASE do read the posting guidehttp://
> >www.R-project.org/posting-guide.html
> > > >> and provide commented, minimal, self-contained, reproducible code.
>
> > > >> --
> > > >> You received this message because you are subscribed to the Google
> > > >> Groups "R-help-archive" group.
> > > >> To post to this group, send email to r-help-archive at googlegroups.com.
> > > >> To unsubscribe from this group, send email to
> > r-help-archive+unsubscribe at googlegroups.com<r-help-archive%2Bunsubscribe at go oglegroups.com>
> > > >> .
> > > >> For more options, visit this group athttp://
> > groups.google.com/group/r-help-archive?hl=en
> > > >> .
>
> > > > ______________________________________________
> > > > R-h... at r-project.org mailing list
> > > >https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guidehttp://
> >www.R-project.org/posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible code.
>
> > > David Winsemius, MD
> > > West Hartford, CT
>
> > > ______________________________________________
> > > R-h... at r-project.org mailing listhttps://
> > stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guidehttp://
> >www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
>
> > ______________________________________________
> > R-h... 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.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list