[R] Read.fwf

Liaw, Andy andy_liaw at merck.com
Wed Sep 15 15:57:11 CEST 2004


It might help to read that help file again:

> d <- paste(c(rep(0, 80), 11111), collapse="")
> d
[1]
"000000000000000000000000000000000000000000000000000000000000000000000000000
0000011111"
> f <- file("try.dat", "w")
> writeLines(d, f)
> writeLines(d, f)
> writeLines(d, f)
> close(f)
> fw <- c(rep(1, 80), 5)
> x <- read.fwf("try.dat", fw)
> x
  V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
V22
1  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
0
2  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
0
3  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0
0
  V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40
V41 V42
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0
2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0
3   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0
  V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60
V61 V62
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0
2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0
3   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0
  V63 V64 V65 V66 V67 V68 V69 V70 V71 V72 V73 V74 V75 V76 V77 V78 V79 V80
V81
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
11111
2   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
11111
3   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
11111

Andy
 

> From: Doran, Harold
> 
> Dear List
> 
> I have a fixed width file with variables of varying width. The help is
> pretty transparent for this feature, but I can't seem to 
> figure out how
> I can make effective use of the package with my data.
> 
> In my dataset, the first 80 columns are of width 1 followed by other
> variables with width larger than 1.
> 
> I think the correct way to do this, by brute force, would be
> 
> > read.fwf(dataset, 1,1,1,...,1,5,...).
> 
> I'm sure I do not need to actually enter 80 "1"s, correct? How might I
> do this more effectively?
> 
> Harold
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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
> 
>




More information about the R-help mailing list