Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R how to get a list of characters in a string

In R how could i get list of characters that are contained in a string. I have provided an example below

somefunction("abc")
should return
"a","b","c"

=============================update1

I am planning to get all the characters, sort them and join them back. I tried paste function but it didnt work :( Any inputs?

sort(strsplit('cba','')[[1]])
paste(sort(strsplit('cba','')[[1]]))
like image 660
user2543622 Avatar asked Dec 04 '25 14:12

user2543622


2 Answers

You can do:

strsplit('abc','')[[1]]
like image 63
runDOSrun Avatar answered Dec 07 '25 03:12

runDOSrun


You could try

 paste(sort(strsplit('cba','')[[1]]), collapse='')
 #[1] "abc"
like image 20
akrun Avatar answered Dec 07 '25 05:12

akrun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!