find indexes in R by not using `which` -


is there faster way search indices rather which %in% r.

i having statement need execute taking lot of time.

statement:

total_authors<-paper_author$author_id[which(paper_author$paper_id%in%paper_author$paper_id[which(paper_author$author_id%in%data_authors[i])])] 

how can done in faster manner?

don't call which. r accepts logical vectors indices, call superfluous. in light of sgibb's comment, can keep which if sure @ least 1 match. (if there no matches, which returns empty vector , instead of nothing. see unexpected behavior using -which() in r when search term not found.)

secondly, code looks little cleaner if use with.

thirdly, think want single index & rather double index.

total_authors <- with(   paper_author,   author_id[paper_id %in% paper_id & author_id %in% data_authors[i] ) 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -