Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split comma delimited string [duplicate]

Tags:

r

I have a string in R in the following form:

"AAAAA","BBBBB","CCCCC",..

And i want to convert it to a standard typical R vector containing the same string elements ("AAAAA", "BBBBB", etc.):

vector<-c("AAAAA","BBBBB","CCCCC",..)

I've read that strsplit could do it, but haven't managed to achieve it.

like image 829
Ghost Avatar asked May 09 '17 18:05

Ghost


People also ask

How do you remove duplicates from a comma separated string?

We can do this with the SPLIT function. This function returns a row of cells divided based on the delimiter. To remove duplicate values, we have to use the UNIQUE function. Since the UNIQUE function works for cells in different rows, we'll have to transpose our SPLIT output using the TRANSPOSE function.

How do I exclude duplicate text in Excel?

In Excel, there are several ways to filter for unique values—or remove duplicate values: To filter for unique values, click Data > Sort & Filter > Advanced. To remove duplicate values, click Data > Data Tools > Remove Duplicates.

How do you remove duplicates in string?

We can remove the duplicate characters from a string by using the simple for loop, sorting, hashing, and IndexOf() method.


1 Answers

strsplit gives you back a list of the character vectors, so if you want it in a single vector, use unlist as well. So,

    unlist(strsplit(string, ","))
like image 94
Adrian Martin Avatar answered Sep 28 '22 08:09

Adrian Martin