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 in light of sgibb's comment, can keep which
. r accepts logical vectors indices, call superfluous.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
Post a Comment