That won't work if any vector has fewer than 5 elements. Maybe

lapply(x, head, n=5)

would work?

On Tue Apr  1 09:24:51 2014, Cook, Malcolm wrote:
in the mean time,

lapply(`[`,x,IntegerList(1:5))

??

  >-----Original Message-----
  >From: bioc-devel-boun...@r-project.org 
[mailto:bioc-devel-boun...@r-project.org] On Behalf Of Michael Lawrence
  >Sent: Tuesday, April 01, 2014 9:21 AM
  >To: bioc-devel@r-project.org
  >Subject: [Bioc-devel] Subsetting Lists by Lists
  >
  >Mostly to Herve:
  >
  >Sometimes we want to pluck the first 1, or 10, or whatever elements from
  >each element of a list. If I had a list 'x', I thought I could do this with:
  >
  >x[IntegerList(1:5)]
  >
  >But it only gives elements 1:5 from x[[1]], not each element of 'x'. In
  >other words, I thought the index would be repped out. Instead, 'x' is
  >subset to the length of 'i', and I'm not sure if that makes sense?
  >
  >But maybe what we really want are pluckHead/Tail, which would be robust to
  >the case that < n elements are in an element. And of course a more general
  >pluck(x, i) to select 'i' from each element, but I wanted the line above to
  >do that.
  >
  >Michael
  >
  >  [[alternative HTML version deleted]]
  >
  >_______________________________________________
  >Bioc-devel@r-project.org mailing list
  >https://stat.ethz.ch/mailman/listinfo/bioc-devel

_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel

_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel

Reply via email to