s-luppescu@uchicago.edu
2001-May-10 21:45 UTC
[R] Scanning data lines with blanks in character vars
Hello, I'm trying to read data in from a file using scan(). The last field is a character string that contains blanks. I had read it in in S-Plus using this code: ifile <- list(entry=0,measure=0,st=0,count=0,score=0, error=0,inmsq=0,instd=0,outms=0,outstd=0,displc=0,ptbis=0,a=0, r="",name="") if.widths <- c(1, 5, 8, 3, 6, 7, 7, 7, 7, 7, 7, 7, 7, 2, 2, 85) d1 <- scan(file=fd,ifile,flush=T,skip=0,widths=if.widths) The name variable is a character string that contains blanks, is of varying length (maximum length is 85), varying number of words and is not surrounded by quotes. It always starts at position 84 on the line and goes to the end of the line. This used to work in S-Plus 3.4 in SunOS (but it seems not to anymore, since we moved to version 5 -- but that's besides the point). Anyway, since there is no widths= in scan() in R, how do I read in a string containing blanks? ______________________________________________________________________ Stuart Luppescu -=-=- University of Chicago $(B:MJ8$HCRF`H~$NIc(B -=-=- s-luppescu at uchicago.edu http://www.consortium-chicago.org/people/sl.html http://musuko.uchicago.edu/pubkey.asc for PGP Public Key ICQ #21172047 AIM: psycho7070 Eat shit -- billions of flies can't be wrong.>> Sent on 10-May-2001 at 15:08:04 with xfmail-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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
2001-May-10 22:11 UTC
[R] Scanning data lines with blanks in character vars
s-luppescu at uchicago.edu writes:> Hello, I'm trying to read data in from a file using scan(). The last field is a > character string that contains blanks. I had read it in in S-Plus using this > code: > > ifile <- list(entry=0,measure=0,st=0,count=0,score=0, > error=0,inmsq=0,instd=0,outms=0,outstd=0,displc=0,ptbis=0,a=0, > r="",name="") > if.widths <- c(1, 5, 8, 3, 6, 7, 7, 7, 7, 7, 7, 7, 7, 2, 2, 85) > d1 <- scan(file=fd,ifile,flush=T,skip=0,widths=if.widths) > > The name variable is a character string that contains blanks, is of varying > length (maximum length is 85), varying number of words and is not surrounded by > quotes. It always starts at position 84 on the line and goes to the end of the > line. > > This used to work in S-Plus 3.4 in SunOS (but it seems not to anymore, since we > moved to version 5 -- but that's besides the point). Anyway, since there is no > widths= in scan() in R, how do I read in a string containing blanks?have a look at read.fwf (doesn't have a what=argument, though) -- 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 D Ripley
2001-May-11 05:59 UTC
[R] Scanning data lines with blanks in character vars
On Thu, 10 May 2001 s-luppescu at uchicago.edu wrote:> Hello, I'm trying to read data in from a file using scan(). The last field is a > character string that contains blanks. I had read it in in S-Plus using this > code: > > ifile <- list(entry=0,measure=0,st=0,count=0,score=0, > error=0,inmsq=0,instd=0,outms=0,outstd=0,displc=0,ptbis=0,a=0, > r="",name="") > if.widths <- c(1, 5, 8, 3, 6, 7, 7, 7, 7, 7, 7, 7, 7, 2, 2, 85) > d1 <- scan(file=fd,ifile,flush=T,skip=0,widths=if.widths) > > The name variable is a character string that contains blanks, is of varying > length (maximum length is 85), varying number of words and is not surrounded by > quotes. It always starts at position 84 on the line and goes to the end of the > line. > > This used to work in S-Plus 3.4 in SunOS (but it seems not to anymore, since we > moved to version 5 -- but that's besides the point). Anyway, since there is no > widths= in scan() in R, how do I read in a string containing blanks?Please see the code for read.fwf for how this is done. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._