R How to separate simple function like“-17+3” in to numbers eg.“-17”and “3”

后端 未结 1 1278
余生分开走
余生分开走 2021-01-28 00:11

my data is like -17+3 2-6 what i need to do is separate each one into two numbers for example: -17+3 into \"-17\" and \"3\" 2-6 into \"2\" and \"-6\" by using R

many man

相关标签:
1条回答
  • 2021-01-28 01:09

    gregexpr and regmatches to the rescue:

    text = '-17+6'
    pattern = '[+-]\\d+'
    matches = gregexpr(pattern, text)
    regmatches(text, matches)
    # [[1]]
    # [1] "-17" "+6"
    
    0 讨论(0)
提交回复
热议问题