Skip to content
Prev 366746 / 398502 Next

Extracting first number after * in a character vector

On 23.01.2017 13:29, Abhinaba Roy wrote:
You know that your vector (called x below) contains an element without 
an asterisk?
If that happened by accident, use
  gsub(".+\\* *([[:digit:]]+).*", "\\1", x)
and if it could happen to have elements without an asterisk or number 
that follows, you can set these results to NA in a seperate step.

Best,
Uwe Ligges