【发布时间】:2019-06-11 17:16:58
【问题描述】:
我有一列文本,想只提取字符串中包含的美元金额,使用美元符号作为字符串的开头。我可以匹配美元符号,但不知道如何在后面直接取数字(并删除逗号)。
我尝试在 str_extract 中使用美元符号作为锚点,但没有得到全部金额。
input <- (c("the sum of $175,000,000 and the sum", "the sum of $20,000,000 and the sum", "the sum of $100,000,000 and the sum"))
df<-as.data.frame(input)
df %>%
mutate(amount = str_extract(input,"^\\$"))
在变异之前运行它看起来像:
input
the sum of $175,000,000 and the sum
the sum of $20,000,000 and the sum
the sum of $100,000,000 and the sum
我希望它看起来像:
input amount
the sum of $175,000,000 and the sum 175000000
the sum of $20,000,000 and the sum 20000000
the sum of $100,000,000 and the sum 100000000
【问题讨论】:
-
你肯定永远不会有任何十进制值吗?这会影响您是否应该删除
.