Skip to content
Prev 308339 / 398503 Next

speeding read.table

Hello,

Try the following, readaing your file into 'x', using readLines.



tc <- textConnection("
TABLE NO.  1
  COL1        COL2        COL3        COL4        COL5 COL6        
COL7        COL8        COL9        COL10 COL11       COL12
   1.0010E+05  0.0000E+00  1.0000E+00  1.0000E+03 -1.0000E+00 
1.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00 0.0000E+00  
0.0000E+00
   1.0010E+05  1.0001E+01  1.0000E+00  1.0000E+03 -1.0000E+00 
1.0000E+00  2.2737E-14 -2.2737E-14  0.0000E+00  1.9281E-08 0.0000E+00  
0.0000E+00
   1.0010E+05  2.4000E+01  1.0000E+00  2.0000E+03 -1.0000E+00 
1.0000E+00  5.7541E-15 -5.7541E-15  0.0000E+00  5.1115E-13 0.0000E+00  
0.0000E+00

TABLE NO.  1
  COL1        COL2        COL3        COL4        COL5 COL6        
COL7        COL8        COL9        COL10 COL11       COL12
   1.0010E+05  0.0000E+00  1.0000E+00  1.0000E+03 -1.0000E+00 
1.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00 0.0000E+00  
0.0000E+00
   1.0010E+05  1.0001E+01  1.0000E+00  1.0000E+03 -1.0000E+00 
1.0000E+00  2.2737E-14 -2.2737E-14  0.0000E+00  1.9281E-08 0.0000E+00  
0.0000E+00
   1.0010E+05  2.4000E+01  1.0000E+00  2.0000E+03 -1.0000E+00 
1.0000E+00  5.7541E-15 -5.7541E-15  0.0000E+00  5.1115E-13 0.0000E+00  
0.0000E+00
")

x <- readLines(tc)
close(tc)

#------------------------ starts here
x <- x[ x != "" ]

i1 <- grep("TABLE", x)
i2 <- grep("COL", x)
y <- x[-c(i1, i2)]

tc <- textConnection(y)
dat <- read.table(tc)
close(tc)

cnames <- unlist(strsplit(x[2], " "))
names(dat) <- cnames[cnames != ""]


Hope this helps,

Rui Barradas
Em 18-10-2012 14:57, Fisher Dennis escreveu: