-2

I have

strQuestions <- c("Q1", "Q22")

I need to get

nQuestions <- c(1,22)

How can I do it nicely? (with stringr?). Thank you

IVIM
  • 2,167
  • 1
  • 15
  • 41
  • 1
    @akrun those two posts have pretty different aims: one is about truncating strings, the other is about substituting commonly accepted English abbreviation standards. Neither are relevant on this post. – camille May 08 '19 at 17:34
  • 4
    @akrun Not my downvote but two hits under the top10 when I google for OP's question title make it a dupe for me. – markus May 08 '19 at 17:44

1 Answers1

2

With stringr:

str_sub(strQuestions, 2, 3)
stringr::str_remove_all(strQuestions,"[A-Za-z]")

You can add the function as.numeric() after.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
demarsylvain
  • 2,103
  • 2
  • 14
  • 33