Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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