-4

i have a vector in a data.frame like this

language     
Enlish
English, Spanish
English,English
English, Spanish
English,Chinses,Spanish,English
Spanish,Chinese,Spanish
English,Spanish, Chinese
......

There are more than 1000 rows in this vector and contain different types of languages. I want to delete all duplicated ones.I hope it can looks like this:

language
English,
English,Spanish,
English,
English,Spanish
English,Chinese,Spanish
Spanish,Chinese
English,Spanish, Chinese
......

I want to get the result with R. Thanks for help!

4

1 回答 1

2

这是一种方法:

您的数据:

language <-readLines(n=7)    
Enlish
English, Spanish
English,English
English, Spanish
English,Chinses,Spanish,English
Spanish,Chinese,Spanish
English,Spanish, Chinese

代码:

lang2 <- strsplit(language, ",\\s*")
## Keep as a list of vectors (more flexible)
lapply(lang2, unique)
## Or paste it together to match your output:
sapply(lapply(lang2, unique), paste, collapse = ",")

## > sapply(lapply(lang2, unique), paste, collapse = ",")
## [1] "Enlish"                  "English,Spanish"        
## [3] "English"                 "English,Spanish"        
## [5] "English,Chinses,Spanish" "Spanish,Chinese"        
## [7] "English,Spanish,Chinese"
于 2013-10-11T18:40:42.763 回答