R: How to split list into several numbers and do the calculation?

后端 未结 3 749
北恋
北恋 2021-01-26 07:42

my data is like: -3+2 41-12 after separating each part by using the following code: eg.

text = \'-3+2\'

pattern = \'-?\\\\d+\'
matches = gre         


        
3条回答
  •  Happy的楠姐
    2021-01-26 08:08

    in your particular case (2 numbers):

    as.integer(a[[1]][1]) + as.integer([[1]][2])

    More generally:

    sum(sapply(a[[1]], as.integer))

提交回复
热议问题