-1
。提取之後是單位「毫升」或「磅」在下面的文本中的數字(僅返回整數):如何查看正則表達式中某些單位的數字?
myText <- 'At 10am we had 40ml of water, 5 lb of meat, 3lb of salt and
20 apples.'
誰能幫助?
。提取之後是單位「毫升」或「磅」在下面的文本中的數字(僅返回整數):如何查看正則表達式中某些單位的數字?
myText <- 'At 10am we had 40ml of water, 5 lb of meat, 3lb of salt and
20 apples.'
誰能幫助?
我們可以使用str_extract
用正則表達式環視
library(stringr)
as.numeric(str_extract_all(myText, "\\d+(?=\\s*(ml|lb))")[[1]])
#[1] 40 5 3
謝謝!它有助於 –
@ T.T謝謝。你也可以勾選[here](https://stackoverflow.com/help/someone-answers) – akrun