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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -