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.
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.
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.
We can remove the duplicate characters from a string by using the simple for loop, sorting, hashing, and IndexOf() method.
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, ","))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With