【发布时间】:2016-08-27 22:16:09
【问题描述】:
我有两个元素的向量。每个元素都包含一个字符串 有两组日期。我需要提取这两个日期中的后者, 并用它们创建一个新的向量或列表。
#webextract vector
webextract <- list("The Employment Situation, December 2006 January 5 \t 8:30 am\r","The Employment Situation, January 2007 \tFeb. 2, 2007\t 8:30 am \r")
#This is how the output of webextract looks like:
[[1]]
[1] The Employment Situation, December 2006 January 5 \t 8:30 am\r
[[2]]
[1] The Employment Situation, January 2007 \tFeb. 2, 2007\t 8:30 am \r
webextract 是网络抓取纯文本 URL 的结果,这就是它看起来像这样的原因。我需要提取的是“1 月 5 日”和“2 月 2 日”。我一直在尝试grep 和strsplit,但没有成功。已经完成了所有相关的 SO 问题,但没有成功。感谢您的帮助。
【问题讨论】:
-
gsub('.+\\s{3}(.+\\d+?).*', '\\1', unlist(webextract))或stringr::str_extract(unlist(webextract), '(?<=\\s{4})\\w.+?\\d+'),也许
标签: r string parsing vector extraction