Last active
August 29, 2015 14:10
-
-
Save ateucher/080e427628dfd86eff73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
srctxt <- "http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.txt" | |
# Import as a character vector first so can get info about length etc. | |
aslines <- readLines(srctxt) | |
# Store the first occurrence of the header row as a character vector | |
header <- strsplit(aslines[8], "\\s+")[[1]] | |
# Count the lines of data (any lines starting with 4 digits) | |
nlines <- length(grep("^\\d{4}", aslines)) | |
# Read the table | |
tbl <- read.table(srctxt, header = FALSE, skip = 7, nrows = nlines, | |
comment.char = "Y", na.strings = c("***", "****"), | |
colClasses = c(rep("numeric", 19), "NULL"), col.names = header) | |
# Set the column headings of Annual Mean columns | |
names(tbl)[c(14,15)] <- paste0("AnnMean_", names(tbl)[c(14,15)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment