How to search for multiple strings and replace them with nothing within a list of strings

前端 未结 3 880
借酒劲吻你
借酒劲吻你 2021-02-05 17:52

I have a column in a dataframe like this:

npt2$name
#  [1] \"Andreas Groll, M.D.\"
#  [2] \"\"
#  [3] \"Pan-Chyr Yang, PHD\"
#  [4] \"Suh-Fang Jeng, Sc.D\"
#  [5         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 18:33

    Either of these:

    gsub("MD|M\\.D\\.|PHD", "", test)  # target specific strings
    gsub("\\,.+$", "", test)        # target all characters after comma
    

    Both Matt Parker above and Tommy below have raised the question whether 'M.R.C.P.', 'PhD', 'D.Phil.' and 'Ph.D.' or other British or Continental designations of doctorate level degrees should be sought out and removed. Perhaps @user56 can advise what the intent was.

提交回复
热议问题