dear members, I have list YH and index vector iuhV. I want to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from YH[[3]]......iuhv[n] from YH[[n]]... How to do this? I searched SO and the internet but was bootless.... Very many thanks for your time and effort..... Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]]
correction....I want the method without a for loop ________________________________ From: akshay kulkarni <akshay_e4 at hotmail.com> Sent: Monday, June 18, 2018 4:25 PM To: R help Mailing list Subject: subsetting lists.... dear members, I have list YH and index vector iuhV. I want to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from YH[[3]]......iuhv[n] from YH[[n]]... How to do this? I searched SO and the internet but was bootless.... Very many thanks for your time and effort..... Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]]
sapply( 1:length(YH), function(i) { YH[[i]][iuhV[i]]}) On Mon, Jun 18, 2018 at 1:55 PM, akshay kulkarni <akshay_e4 at hotmail.com> wrote:> dear members, > I have list YH and index vector iuhV. I want > to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from > YH[[3]]......iuhv[n] from YH[[n]]... > > How to do this? > I searched SO and the internet but was bootless.... > > Very many thanks for your time and effort..... > Yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
My response does not have an explicit for loop. On Mon, Jun 18, 2018 at 2:15 PM, akshay kulkarni <akshay_e4 at hotmail.com> wrote:> correction....I want the method without a for loop > ________________________________ > From: akshay kulkarni <akshay_e4 at hotmail.com> > Sent: Monday, June 18, 2018 4:25 PM > To: R help Mailing list > Subject: subsetting lists.... > > dear members, > I have list YH and index vector iuhV. I want > to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from > YH[[3]]......iuhv[n] from YH[[n]]... > > How to do this? > I searched SO and the internet but was bootless.... > > Very many thanks for your time and effort..... > Yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
> On Jun 18, 2018, at 4:15 AM, akshay kulkarni <akshay_e4 at hotmail.com> wrote: > > correction....I want the method without a for loopHere are two. The first is more readable, but the second is 5 times faster. mapply("[", YH, iuhV) unlist(YH, recursive = FALSE, use.names = FALSE)[cumsum( lengths(YH)) - lengths(YH) + iuhV] HTH, Chuck> ________________________________ > From: akshay kulkarni <akshay_e4 at hotmail.com> > Sent: Monday, June 18, 2018 4:25 PM > To: R help Mailing list > Subject: subsetting lists.... > > dear members, > I have list YH and index vector iuhV. I want to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from YH[[3]]......iuhv[n] from YH[[n]]... > > How to do this? > I searched SO and the internet but was bootless.... > > Very many thanks for your time and effort..... > Yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] >