Thanks Martin Morgan. Thats works excellent on a large data . Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com
----- Original Message ----- From: Martin Morgan <martin.mor...@roswellpark.org> To: Mohammad Tanvir Ahamed <mashra...@yahoo.com>; R-help Mailing List <r-help@r-project.org> Sent: Tuesday, 28 June 2016, 11:07 Subject: Re: [R] Get the location of a numeric element in a list On 06/28/2016 03:03 AM, Mohammad Tanvir Ahamed via R-help wrote: > Can any one please help me. I will apply this for a very large list, about > 400k vector in a list and vector size is unequal and large > > Example : > Input: > a <- c(1,3,6,9,25,100) > b<-c(10,7,20,2,25) > c<-c(1,7,5,15,25,300,1000) > d<-list(a,b,c) > > Expected outcome : > # When looking for 1 in d > c(1,3) > > # When looking for 7 in d > > c(2,3) > > # when looking for 25 in d > c(1,2,3) > # When looking for 50 in d > NULL or 0 Make a vector of queries queries = c(1, 7, 25, 50) Create a factor of unlist(d), using queries as levels. Create a vector rep(seq_along(d), lengths(d)), and split it into groups defined by f f = factor(unlist(d, use.names=FALSE), levels=queries) split(rep(seq_along(d), lengths(d)), f) Martin Morgan > > > Thanks in advance !! > > > > > > Tanvir Ahamed > Göteborg, Sweden | mashra...@yahoo.com > > ______________________________________________ > R-help@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. > This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. ______________________________________________ R-help@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.