我使用R进行文本分析。我使用“readtext”函数从pdf中提取文本。然而,正如你所能想象的,这是相当混乱的。为了不同的目的,我用“gsub”替换文本。其一般目标是使用一种类型的分隔符“%”将记录拆分为行,使用另一种分隔符“@”分隔列。我完成了第一件事,但对如何完成后一件事感到不知所措。在dataframe中找到的数据示例如下:
895“流动个案-混合发展计划@n@公布:六月六日,1994@作者: Baker A,Honigfeld S,Lieberman R,Tucker AM,Weiner JP@Country: United States @Journal:Project final report。巴尔的摩,医学博士,美国:约翰霍普金斯大学和Aetna健康计划。约翰霍普金斯大学和爱塔纳健康计划,美国作为美国[…]
896“救护小组:军事医疗使用评估@出版日期:6月6日,1994@作者: Bolling DR,Georgoulakis JM,Guillen AC@Country: United States @Journal:Fort休斯顿,TX,USA: United States Guillen for Healthcare Education and Studies,出版物#HR 94-\n 004。美国陆军医疗保健教育中心和…@网址:http://oai.dtic.mil/oai/oai?verb=getRecord&metadataPrefix=html&identifier=ADA27804“
我想获取这些数据,并将@Published、@Journal、@URL拆分为列-c(“已发布”、“作者”、“日志”、"URL")。
有什么建议吗?
提前感谢!
发布于 2017-08-15 03:37:40
这似乎是可行的:
dfr <- data.frame(TEXT=c("The ambulatory case-mix development project\n@Published:: June 6, 1994@Authors: Baker A, Honigfeld S, Lieberman R, Tucker AM, Weiner JP@Country: United States @Journal:Project final report. Baltimore, MD, USA: Johns Hopkins University and Aetna Health Plans. Johns Hopkins\nUniversity and Aetna Health Plans, USA As the US […",
"Ambulatory Care Groups: an evaluation for military health care use@Published:: June 6, 1994@Authors: Bolling DR, Georgoulakis JM, Guillen AC@Country: United States @Journal:Fort Sam Houston, TX, USA: United States Army Center for Healthcare Education and Studies, publication #HR 94-\n004. United States Army Center for Healthcare Education and […]@URL: http://oai.dtic.mil/oai/oai?verb=getRecord&metadataPrefix=html&identifier=ADA27804"),
stringsAsFactors = FALSE)
library(magrittr)
do.call(rbind, strsplit(dfr$TEXT, "@Published::|@Authors:|@Country:|@Journal:")) %>%
as.data.frame %>%
setNames(nm = c("Preamble","Published","Authors","Country","Journal"))基本上将文本拆分为四个字段中的一个(注意双::发布后!),行绑定结果,转换为dataframe,并给出一些名称。
https://stackoverflow.com/questions/45685974
复制相似问题