Extracting unique numbers from string in R

前端 未结 7 2069
Happy的楠姐
Happy的楠姐 2020-11-27 05:11

I have a list of strings which contain random characters such as:

list=list()
list[1] = \"djud7+dg[a]hs667\"
list[2] = \"7fd*hac11(5)\"
list[3] = \"2tu,g7gka         


        
相关标签:
7条回答
  • 2020-11-27 06:08

    Use strsplit using pattern as the inverse of numeric digits: 0-9

    For the example you have provided, do this:

    tmp <- sapply(list, function (k) strsplit(k, "[^0-9]"))
    

    Then simply take a union of all `sets' in the list, like so:

    tmp <- Reduce(union, tmp)
    

    Then you only have to remove the empty string.

    0 讨论(0)
提交回复
热议问题