[R] how to divide a string into characters? - for comparing strings that is
jerome at hivnet.ubc.ca
Fri Jul 18 00:29:01 CEST 2003
Here is a way of doing by splitting the character strings.
x <- "ABD"
y <- "ADE"
x <- unlist(strsplit(x,""))
y <- unlist(strsplit(y,""))
On July 17, 2003 03:07 pm, David Andel wrote:
> 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,
> R-help at stat.math.ethz.ch mailing list
More information about the R-help