[R] character to vector

2006-07-21 Thread ajkorman
I have an object of mode character that contains a long sequence of letters. 
How can I convert this object into a vector with each element of the vector
containing a single letter?  Essentially, I want to break the long string of
letters into many individual letters.

Thanks for the help.

Alex

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] character to vector

2006-07-21 Thread Marc Schwartz (via MN)
On Fri, 2006-07-21 at 15:15 -0500, [EMAIL PROTECTED] wrote:
 I have an object of mode character that contains a long sequence of letters. 
 How can I convert this object into a vector with each element of the vector
 containing a single letter?  Essentially, I want to break the long string of
 letters into many individual letters.
 
 Thanks for the help.
 
 Alex

 letters
 [1] a b c d e f g h i j k l m n o p q
[18] r s t u v w x y z

 MyChar - paste(letters, collapse = )

 MyChar
[1] abcdefghijklmnopqrstuvwxyz

 MyVec - unlist(strsplit(MyChar, ))

 MyVec
 [1] a b c d e f g h i j k l m n o p q
[18] r s t u v w x y z

See ?strsplit and ?unlist and of course, ?paste for the reverse
operation as above.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.