- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个很大的数据集,专门用于生物期刊,由不同的人长期编写。因此,数据不是单一格式。例如,在“作者”列中,我可以找到同一个人的约翰·史密斯,史密斯·约翰,史密斯·J等。我什至无法执行最简单的 Action 。例如,我不知道哪些作者写的文章最多。
R中是否有任何方法可以确定不同名称中的大多数符号是否相同,将它们视为相同的元素?
最佳答案
有一些可以帮助您解决此问题的软件包,其中一些已在注释中列出。但是,如果您不想使用它们,尽管我会尝试用R编写一些可能对您有所帮助的东西。该代码将使“John Smith”与“J Smith”,“John Smith”,“Smith John”,“John S”匹配。同时,它不会匹配“John Sally”之类的东西。
# generate some random names
names = c(
"John Smith",
"Wigberht Ernust",
"Samir Henning",
"Everette Arron",
"Erik Conor",
"Smith J",
"Smith John",
"John S",
"John Sally"
);
# split those names and get all ways to write that name
split_names = lapply(
X = names,
FUN = function(x){
print(x);
# split by a space
c_split = unlist(x = strsplit(x = x, split = " "));
# get both combinations of c_split to compensate for order
c_splits = list(c_split, rev(x = c_split));
# return c_splits
c_splits;
}
)
# suppose we're looking for John Smith
search_for = "John Smith";
# split it by " " and then find all ways to write that name
search_for_split = unlist(x = strsplit(x = x, split = " "));
search_for_split = list(search_for_split, rev(x = search_for_split));
# initialise a vector containing if search_for was matched in names
match_statuses = c();
# for each name that's been split
for(i in 1:length(x = names)){
# the match status for the current name
match_status = FALSE;
# the current split name
c_split_name = split_names[[i]];
# for each element in search_for_split
for(j in 1:length(x = search_for_split)){
# the current combination of name
c_search_for_split_names = search_for_split[[j]];
# for each element in c_split_name
for(k in 1:length(x = c_split_name)){
# the current combination of current split name
c_c_split_name = c_split_name[[k]];
# if there's a match, or the length of grep (a pattern finding function is
# greater than zero)
if(
# is c_search_for_split_names first element in c_c_split_name first
# element
length(
x = grep(
pattern = c_search_for_split_names[1],
x = c_c_split_name[1]
)
) > 0 &&
# is c_search_for_split_names second element in c_c_split_name second
# element
length(
x = grep(
pattern = c_search_for_split_names[2],
x = c_c_split_name[2]
)
) > 0 ||
# or, is c_c_split_name first element in c_search_for_split_names first
# element
length(
x = grep(
pattern = c_c_split_name[1],
x = c_search_for_split_names[1]
)
) > 0 &&
# is c_c_split_name second element in c_search_for_split_names second
# element
length(
x = grep(
pattern = c_c_split_name[2],
x = c_search_for_split_names[2]
)
) > 0
){
# if this is the case, update match status to TRUE
match_status = TRUE;
} else {
# otherwise, don't update match status
}
}
}
# append match_status to the match_statuses list
match_statuses = c(match_statuses, match_status);
}
search_for;
[1] "John Smith"
cbind(names, match_statuses);
names match_statuses
[1,] "John Smith" "TRUE"
[2,] "Wigberht Ernust" "FALSE"
[3,] "Samir Henning" "FALSE"
[4,] "Everette Arron" "FALSE"
[5,] "Erik Conor" "FALSE"
[6,] "Smith J" "TRUE"
[7,] "Smith John" "TRUE"
[8,] "John S" "TRUE"
[9,] "John Sally" "FALSE"
for
循环可能很慢。如果您要处理大量名称,请查看Rcpp
。 search_for
将其应用于其他名称。 关于r - 如何在R中执行近似(模糊)名称匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22894265/
所以我必须用以下方法来近似 Pi:4*(1-1/3+1/5-1/7+1/9-...)。它也应该基于迭代次数。所以函数应该是这样的: >>> piApprox(1) 4.0 >>> piApprox(1
输入:图 G 输出:多个独立集,使得一个节点对所有独立集的成员资格是唯一的。因此,节点与它自己的集合中的任何节点都没有连接。这是一个示例路径。 由于这里需要澄清,因此再次改写: 将给定的图划分为多个集
我已经使用查找表和低阶多项式近似实现了定点 log2 函数,但对整个 32 位定点范围 [-1,+1) 的准确度不太满意。输入格式为 s0.31,输出格式为 s15.16。 我在这里发布这个问题,以便
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它可以帮助我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注
我的目标是近似二项式变量总和的分布。我使用以下纸张The Distribution of a Sum of Binomial Random Variables作者:肯·巴特勒和迈克尔·斯蒂芬斯。 我想
我知道有方法 approximate cubic Bezier curves ( this page 也是一个很好的引用),但是有没有更快的方法来逼近 N 次贝塞尔曲线?还是只能使用下面的概括? 来自
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它有助于我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注意
我是 C++ 和编码本身的初学者,所以请原谅任何词汇错误。我找不到这个具体问题,但在互联网上找到了类似的问题,但我仍然很难获得我需要的结果。 所以我使用莱布尼茨公式来近似 pi,即: pi = 4 ·
有多种方法可以通过显示名称查找联系人。例如这个答案Android - Find a contact by display name 但是我需要找到模糊匹配的联系人。例如如果找不到“Kim”,我需要返回
我一直在尝试使用以下代码使用级数表示来近似 e 以获得尽可能多的精度数字,但无论我计算多少项,精度数字的数量似乎都保持不变。即: 2.718281984329223632812500000000000
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它可以帮助我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它可以帮助我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注
大多数拥有计算机科学学位的人肯定知道什么是Big O stands for。 它有助于我们衡量一个算法的实际效率,如果您知道在what category the problem you are try
大多数拥有计算机科学学位的人肯定知道什么是Big O stands for。 它有助于我们衡量一个算法的实际效率,如果您知道在what category the problem you are try
我做了很多随机的数学程序来帮助我完成作业(合成除法是最有趣的),现在我想反转一个激进的表达式。 例如,在我方便的 TI 计算器中我得到 .2360679775 好吧,我想将该数字转换为等效的无理数表达
我可以通过 CPU 分析器看到,compute_variances() 是我项目的瓶颈。 % cumulative self self total
大多数拥有 CS 学位的人肯定知道什么 Big O stands for . 它帮助我们衡量算法的可扩展性。 但我很好奇,你如何计算或近似算法的复杂性? 最佳答案 我会尽我所能用简单的术语在这里解释它
这是迄今为止我的代码, from math import * def main(): sides = eval(input("Enter the number of sides:"))
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
大多数拥有 CS 学位的人肯定知道什么 Big O stands for . 它帮助我们衡量算法的扩展性。 但我很好奇,你如何计算或近似算法的复杂性? 最佳答案 我会尽我所能用简单的术语在这里解释它,
我是一名优秀的程序员,十分优秀!