我试图仅在“ =”字符串后提取数字
strings <- c("1t clever=120","3c stupid=-150 bad","5k high iq=150 good")
并尝试
as.numeric(gsub("[^\\d]+","",strings,perl = TRUE))
这使
[1] 1120 3150 5150
预期的输出
120 -150 150
如何获得此输出?
我们可以试试
library(stringr)
as.numeric(str_extract(strings, "(?<==)-?\\d+"))
#[1] 120 -150 150
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句