本文介绍了R中的高效编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有类似

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
The International Centre for Genetic Engineering and Biotechnology, Padriciano 66,
Trieste, Italy


International Centre for Genetic Engineering and Biotechnology, Padriciano 99, 34149
Trieste, Italy

现在,我必须检查author_name和author_name1(name_dist)之间的每一行strindist以及author_affiliation与author_affiliation1(aff_sit.)之间的stringdist.

Now I have to check for each row strindist between author_name and author_name1(name_dist) and the stringdist between author_affiliation vs author_affiliation1(aff_sit.

我正在使用

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 this is using a lot of time.How could this be done efficiently?

谢谢

推荐答案

您可以直接对其矢量化

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")

这篇关于R中的高效编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 00:55