Removing duplicate words in a string in R

后端 未结 4 1095
栀梦
栀梦 2020-12-11 03:47

Just to help someone who\'s just voluntarily removed their question, following a request for code he tried and other comments. Let\'s assume they tried something like this:

4条回答
  •  情歌与酒
    2020-12-11 04:09

    If you are still interested in alternate solutions you can use unique which slightly simplifies your code.

    paste(unique(d), collapse = ' ')
    

    As per the comment by Thomas, you probably do want to remove punctuation. R's gsub has some nice internal patterns you can use instead of strict regex. Of course you can always specify specific instances if you want to do some more refined regex.

    d <- gsub("[[:punct:]]", "", d)
    

提交回复
热议问题