Use gsub()
with a regular expression
x <- c("Resistance_Test DevID (Ohms) 428", "Diode_Test SUBLo (V) 353")
ptn <- "(.*? ){3}"
gsub(ptn, "", x)
[1] "428" "353"
This works because the regular expression (.*? ){3}
finds exactly three {3}
sets of characters followed by a space (.*? )
, and then replaces this with ane empty string.
See ?gsub
and ?regexp
for more information.
If your data has structure that you don't mention in your question, then possibly the regular expression becomes even easier.
For example, if you are always interested in the last word of each line:
ptn <- "(.*? )"
gsub(ptn, "", x)
Or perhaps you know for sure you can only search for digits and discard everything else:
ptn <- "\D"
gsub(ptn, "", x)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…