删除一行中的重复单词

removing duplicate words in a row

我在 table 中有一列如下

    Col1
    ========================
    "No","No","No","No","No"
    "No","No","No"
     Yes
     No
    "Yes","Yes","Yes","Yes"
    "Yes","No","Yes", "Yes

我正在尝试删除重复的“否”和“是”并创建这样的列

            Col1
    ========================
     No
     No
     Yes
     No
     Yes
     Yes, No

我从

开始
     kickDuplicates <- c("No","Yes")
     # create a list of vectors of place names
     broken <- strsplit(Table1$Col1, ",")
     # paste each broken vector of place names back together
     # .......kicking out duplicated instances of the chosen names
     Table1$Col1 <- sapply(broken, FUN = function(x)  paste(x[!duplicated(x)  
     | !x %in% kickDuplicates ], collapse = ", "))

但这不起作用,我得到与以前相同的原始列和重复项,谁能告诉我哪里出错了?

c("\"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\"", 
"\"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"Yes\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\"", 
"\"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\"", 
"\"No\", \"No\"", "\"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\", \"No\"", 
"No")

我认为这将作为你的最后一行:

Table1$Col1 <- sapply(broken,function(x) paste(unique(x), collapse=','))

因为我是包 functional 的粉丝,这里有一个等价物:

sapply(broken, Compose(unique, Curry(paste, collapse=',')))