Extracting unique numbers from string in R

前端 未结 7 2110
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 05:52

    A stringr solution with str_match_all and piped operators. For the first solution:

    library(stringr)
    str_match_all(ll, "[0-9]+") %>% unlist %>% unique %>% as.numeric
    

    Second solution:

    str_match_all(ll, "[0-9]") %>% unlist %>% unique %>% as.numeric
    

    (Note: I've also called the list ll)

提交回复
热议问题