[R] how to divide a string into characters? - for comparing strings that is

David Andel andel at ifi.unizh.ch
Fri Jul 18 00:07:43 CEST 2003


I am searching for a way to do something like "ABC" -> c("A","B","C"). How can this be accomplished?

I tried cut() and split(), but they do something else, it seems.

The purpose for doing this is to find the number of common (and uncommon) characters, i.e. ultimately I want something like this:

> foo("ABD","ADE")
c(2,1) # 2 in x are in y, 1 in y is not in x
> foo("AB","ADE")
c(1,2) # 1 in x is in y, 2 in y are not in x

Maybe I even do not need the string splitting?

I hope I was clear in stating my problem.

Thank you for your valuable input,

More information about the R-help mailing list