Extract all numbers from a single string in R

后端 未结 4 1131
夕颜
夕颜 2020-11-30 07:54

Let\'s imagine you have a string:

strLine <- \"The transactions (on your account) were as follows: 0 3,000 (500) 0 2.25 (1,200)\"

Is the

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 08:12

    What for me worked perfectly when working on single strings in a data frame (One string per row in same column) was the following:

    library(taRifx)
    DataFrame$Numbers<-as.character(destring(DataFrame$Strings, keep="0-9.-"))
    

    The results are in a new column from the same data frame.

提交回复
热议问题