从R中的文本中提取任何格式的日期 [英] Extract Dates in any format from Text in R

查看:117
本文介绍了从R中的文本中提取任何格式的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从给定文本中提取日期,日期可以是任何格式
2018年4月10日,10-04-2018,10/04/2018,2018/04/10,04.10.2018喜欢其他格式....

I want to Extract Dates from the Given Text , Dates can be in any format April 10 2018, 10-04-2018 , 10/04/2018, 2018/04/10, 04.10.2018 like in other formats ....

我有新闻数据,想从文本中提取日期

I have news data and want to extract dates from the text

例如:我的朋友将于2018年7月10日或2018年7月10日到来

我要从中提取日期给定的文本

i want to extract date from the given text

请帮助

预先感谢

推荐答案

我们使用 str_extract 提取它,然后使用 anydate 提取格式

we extract it using str_extract and then with anydate get the format

library(anytime)
library(stringr)
anydate(str_extract_all(str1, "[[:alnum:]]+[ /]*\\d{2}[ /]*\\d{4}")[[1]])
#[1] "2018-07-10" "2018-10-07"



数据



data

str1 <- "My Friend is coming on july 10 2018 or 10/07/2018"

这篇关于从R中的文本中提取任何格式的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆