【问题标题】:How to extract number from string? [duplicate]如何从字符串中提取数字? [复制]
【发布时间】:2019-05-08 17:08:41
【问题描述】:

我有

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

我需要得到

nQuestions <- c(1,22)

我怎样才能做得很好? (用stringr?)。谢谢

【问题讨论】:

  • @akrun 这两个帖子的目标完全不同:一个是关于截断字符串,另一个是关于替换普遍接受的英文缩写标准。与这篇文章都不相关。

标签: r stringr


【解决方案1】:

stringr:

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

你可以在后面加上函数as.numeric()

【讨论】:

    猜你喜欢
    • 2021-05-10
    • 2021-03-06
    • 2019-10-15
    • 1970-01-01
    • 2017-09-24
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多