loops - efficient programming in R -


i have data

author_id paper_id confirmed     author_name1   author_affiliation1         author_name       826    25733         1     emanuele buratti  genetic engineering    emanuele buratti    826    25733         1     emanuele buratti  international center   emanuele buratti    826    47276         1     emanuele buratti                         emanuele buratti    826    77012         1     emanuele buratti                         emanuele buratti    826    77012         1     emanuele buratti                         emanuele buratti    826    79468         1     emanuele buratti                         emanuele buratti  author_affiliation genetic enginereing                                                                                                 international centre genetic engineering , biotechnology, padriciano 66,         trieste, italy   international centre genetic engineering , biotechnology, padriciano 99, 34149                          trieste, italy 

now have check each row strindist between author_name , author_name1(name_dist) , stringdist between author_affiliation vs author_affiliation1(aff_sit.

i using

name_dist<-vector() aff_dist<-vector() for(i in 1:nrow(mer1)) {  name_dist[i]<-stringdist(mer1$author_name1[i],mer1$author_name[i],method="lv")  aff_dist[i]<-stringdist(mer1$author_affiliation1[i],mer1$author_affiliation[i],method="lv")   } 

but using lot of time.how done efficiently?

thanks

you can directly vectorize it

i=1:nrow(mer1) name_dist<-stringdist(mer1$author_name1[i],mer1$author_name[i],method="lv") aff_dist<-stringdist(mer1$author_affiliation1[i],mer1$author_affiliation[i],method="lv") 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -