[R] Get the location of a numeric element in a list

Jim Lemon drjimlemon at gmail.com
Tue Jun 28 10:14:29 CEST 2016


Hi Tanvir,
How about this:

value<-1
(1:length(d))[unlist(lapply(lapply(d,"==",value),any))]

Jim


On Tue, Jun 28, 2016 at 5:03 PM, Mohammad Tanvir Ahamed via R-help
<r-help at r-project.org> 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
>
>
> Thanks in advance !!
>
>
>
>
>
> Tanvir Ahamed
> Göteborg, Sweden  |  mashranga at yahoo.com
>
> ______________________________________________
> 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.



More information about the R-help mailing list