Extract text name from String

后端 未结 5 574
星月不相逢
星月不相逢 2020-12-18 16:41

I have a column with value as

\"RED LOBSTER CA04606\" or \"Red Lobster NewYork WY245\" n so on

How can I extract just the name Red Lobster or Red Lobster N

5条回答
  •  攒了一身酷
    2020-12-18 17:01

    Using a combination of strsplit and grepl

     sapply(strsplit(x, ' '), function(x) paste(x[!grepl('[[:digit:]]',x)], collapse = ' '))
    

    This splits by space, then tests whether there are digits splitted vector, and only pastes together those without numbers.

提交回复
热议问题