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

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -