SHARE
TWEET

Untitled

a guest Feb 11th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #################
  2. ### Data load ###
  3. #################
  4. # https://data.giss.nasa.gov/gistemp/graphs/
  5. # https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States
  6. # Drop Hayes and Garfield (1880-1881) since the temperature record starts in the middle
  7. # of Hayes' term and no trend can be calculated for Garfield (< 1 year in office)
  8. dat = read.csv("globalTemp.csv", stringsAsFactors = F)
  9. dat = dat[-(1:2), ]
  10.  
  11.  
  12. ############
  13. ### Prep ###
  14. ############
  15. pres = unique(unlist(strsplit(dat$President, "/")))
  16. res  = data.frame(pres  = pres,
  17.                   party = NA,
  18.                   t0    = NA,
  19.                   tF    = NA,
  20.                   yrs   = NA,
  21.                   slope = NA,
  22.                   stringsAsFactors = F)
  23.  
  24. for(i in 1:length(pres)){
  25.   idx          = grep(pres[i], dat$President)
  26.   res$party[i] = dat$Party[which(dat$President == pres[i])[1]]
  27.   res$t0[i]    = head(dat$Year[idx], 1)
  28.   res$tF[i]    = tail(dat$Year[idx], 1)
  29.   res$yrs[i]   = res$tF[i] - res$t0[i]
  30.   res$slope[i] = coef(lm(Temp~Year, dat[idx,]))[2]
  31.   res$total[i] = res$yrs[i]*res$slope[i]
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top