Sandra Romero
2002-Feb-14 17:24 UTC
[R] How to read a long string of characters as a vector
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. Thank you in advanced. Sandra _________________________________________________________ Informaci?n de Estados Unidos y Am?rica Latina, en Yahoo! Noticias. Vis?tanos en http://noticias.espanol.yahoo.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Feb-14 17:36 UTC
[R] How to read a long string of characters as a vector
Sandra Romero <srhidalgo at yahoo.com> writes:> 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.You probably can't do it on input, but have a look at strsplit(). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian Ripley
2002-Feb-14 17:39 UTC
[R] How to read a long string of characters as a vector
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.use scan, then strsplit, or if you prefer, read.fwf> > Thank you in advanced. > > Sandra > > _________________________________________________________ > > Información de Estados Unidos y América Latina, en Yahoo! Noticias. > Visítanos en http://noticias.espanol.yahoo.com > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Sandra, paste(unlist(strsplit("yourstring", "")), sep = "", collapse = ",") will give you y,o,u,r,s,t,r,i,n,g. Jianhua -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2002-Feb-14 18:02 UTC
[R] How to read a long string of characters as a vector
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._