[R] Scanning data lines with blanks in character vars

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri May 11 00:11:56 CEST 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list