[R] How to read a long string of characters as a vector

Thomas Lumley tlumley at u.washington.edu
Thu Feb 14 19:02:11 CET 2002


On Thu, 14 Feb 2002, [iso-8859-1] Sandra Romero wrote:

> Dear R users,
>
> I would really appreciate some help, I have a plain
> text file which contains info like
>
> NANATGGGGGGGCCCAGCTTGAATTCCCNTCCCCNTTCCCATCCAGGCC
>
> I would like to read it as a vector, for example,
> (N,A,N,A,T,G,G,G,G,G,G,G,C,C,C,........)
>
> I've tried commands such as read.table and scan but I
> don't get what I want.
>

Two possibilities
1/ Read it in as a long string and then split it
eg
   > a<-"QWERTYUIOP"
   > strsplit(a,"")
   [[1]]
    [1] "Q" "W" "E" "R" "T" "Y" "U" "I" "O" "P"

2/ If you actually have multiple lines like this and want a data frame
then read.fwf() should help.

	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list