从字符串中提取数据格式

时间:2017-02-16 15:50:13

标签: r

有人可以告诉我如何从下面的句子中提取日期:

head(df),结果:

 X..Indicadores...APM...Aplicacoes_e_Transacoes...PlainText
1                        # Application: Central Analysis Server
2                                       # Application Id: CVENT
3          # Data View: Application, transaction, and tier data
4                                          # Data View Id: Tier
5              # Filters: Tier=LAN | WAN | Enterprise Synthetic
6                             # 22/01/17 00:00 - 23/01/17 00:00

我只需要第一个日期,在6º行:

22/01/17

有人可以帮助我

1 个答案:

答案 0 :(得分:0)

data.frame(
  `X..Indicadores...APM...Aplicacoes_e_Transacoes...PlainText`=
  c("# Application: Central Analysis Server",
    "# Application Id: CVENT", 
    "# Data View: Application, transaction, and tier data", 
    "# Data View Id: Tier", 
    "# Filters: Tier=LAN | WAN | Enterprise Synthetic", 
    "# 22/01/17 00:00 - 23/01/17 00:00"), stringsAsFactors=FALSE) -> df

library(stringi)

stri_extract_first_regex(df[6,1], "([[:digit:]]+/[[:digit:]]+/[[:digit:]]+)")
## [1] "22/01/17"