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

Roger D. Peng rpeng at stat.ucla.edu
Fri Jul 18 00:21:08 CEST 2003



David Andel wrote:

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

strsplit("ABC", "")[[1]]

>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,
>David
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
>  
>




More information about the R-help mailing list