[R] regular expressions : extracting numbers
Christian Ritz
ritz at kvl.dk
Mon Jul 30 14:18:19 CEST 2007
Dear David,
does the following work for you?
sVec <- c("lema, rb 2%", "rb 2%", "rb 3%", "rb 4%", "rb 3%", "rb 2%,mineuse", "rb", "rb",
"rb 12", "rb", "rj 30%", "rb", "rb", "rb 25%", "rb", "rb", "rb", "rj, rb")
reVec <- regexpr("[[:digit:]]+", sVec)
# see ?regex for details on '[:digit:]' and '+'
substr(sVec ,start = reVec, stop=reVec + attr(reVec, "match.length") - 1)
# see ?substr for details
Christian
More information about the R-help
mailing list