Posts

Showing posts with the label R code

R code for my Seasonal Trends graph

Image
I had a request for the code I used to generate the graphs in my Seasonal Trends post. While it looks complex, the R code for it is very simple IF you have the data ready.    I'm assuming that you already have the temperature dataset you want as an R object (I have several datasets in an object I simply call "monthly": GISS, Berkeley Earth, Cowtan-Way, HadCRUT4, UAH, and RSS, along with the year/decimal month Time, Year, and numeric Month).  The code I used to generate the graph is as follows: #Create separate datasets for each season monthly.79<-subset(monthly, Time>=1978.92 & Time<2013.91) DJF<-subset(monthly.79, Month=="12" | Month =="1" | Month=="2") DJF$Year_2 <- numeric (length (DJF$Year)) for (i in 1:length (DJF$Year) ) {         if ( DJF$Month [i] == 12) {                 DJF$Year_2[i] <-   DJF$Year [i] + 1         }     ...