如何从非日期文本中提取一个三位数?
示例:
"she is born on 02-05-1934 and she is 200 years old."
那么,我如何从这里提取200?
我正在使用以下代码:
str_extract(data,"[[:digit:]]{3}")
但它返回的输出是-193
。
library(stringr)
as.numeric(str_extract(str1, "(?<=\\s)\\d+(?=\\s)"))
#[1] 200
str1 <- "she is born on 02-05-1934 and she is 200 years old"
str_extract(str1, "(?<=\\s)\\d+(?=\\s)")
。 - akrunas.numeric(str_extract(data,"\\s[[:digit:]]{3}\\s"))
- Ronak Shah