Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function that extracts each unique character in a string

Tags:

r

Let's say that I have a string "rrkn". Is there a function in R that'll return a vector "r", "k", "n" (i.e. each unique character in the string)?

like image 861
user46226 Avatar asked Aug 04 '15 16:08

user46226


1 Answers

If you want to make it slightly less cumbersome to type:

uniqchars <- function(x) unique(strsplit(x, "")[[1]]) 
like image 147
hrbrmstr Avatar answered Oct 30 '22 06:10

hrbrmstr