Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Last active August 29, 2015 13:58
Show Gist options
  • Save mdlincoln/10171846 to your computer and use it in GitHub Desktop.
Save mdlincoln/10171846 to your computer and use it in GitHub Desktop.
library("mvbutils")
path <- "state07_DE.txt"
col.widths <- c(6, 4, 2, 4)
table.header <- c("COOP.ID", "YEAR", "MONTH", "ELEMENT")
for(i in 1:31) {
new.widths <- c(5, 1, 1, 1)
new.header <- c(paste("VALUE",i, sep=""),
paste("MFLAG",i, sep=""),
paste("QFLAG",i, sep=""),
paste("SFLAG",i, sep=""))
col.widths <- append(col.widths, new.widths)
table.header <- append(table.header, new.header)
}
print("Time for regular read:")
system.time(data1 <- read.fwf(file=path, widths=col.widths, header=FALSE, col.names=table.header))
print("Time for faster.read.fwf")
system.time(data2 <- fast.read.fwf(file=path, width=col.widths, col.names=table.header))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment