Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################
- ### Data load ###
- #################
- # https://data.giss.nasa.gov/gistemp/graphs/
- # https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States
- # Drop Hayes and Garfield (1880-1881) since the temperature record starts in the middle
- # of Hayes' term and no trend can be calculated for Garfield (< 1 year in office)
- dat = read.csv("globalTemp.csv", stringsAsFactors = F)
- dat = dat[-(1:2), ]
- ############
- ### Prep ###
- ############
- pres = unique(unlist(strsplit(dat$President, "/")))
- res = data.frame(pres = pres,
- party = NA,
- t0 = NA,
- tF = NA,
- yrs = NA,
- slope = NA,
- stringsAsFactors = F)
- for(i in 1:length(pres)){
- idx = grep(pres[i], dat$President)
- res$party[i] = dat$Party[which(dat$President == pres[i])[1]]
- res$t0[i] = head(dat$Year[idx], 1)
- res$tF[i] = tail(dat$Year[idx], 1)
- res$yrs[i] = res$tF[i] - res$t0[i]
- res$slope[i] = coef(lm(Temp~Year, dat[idx,]))[2]
- res$total[i] = res$yrs[i]*res$slope[i]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement