This document is an extention of the rpubs work found here and related to the work found on my website here.

#install.packages("lubridate")
#install.packages("zoo")
#install.packages("xts")
#install.packages("hydroTSM")

setwd("//Volumes//Donals_Toshiba_External//U_Drive//ESCI597")
CRLA.SNOTEL=read.csv("CRLA_SNOTEL_slim_corrected.csv", header=T, stringsAsFactors=F)

CRLA.SNOTEL=read.csv("CRLA_SNOTEL_slim_corrected.csv", header=T)

CRLA.SWEts <- ts(CRLA.SNOTEL[2],frequency = 1)
CRLA.PPTaccts <- ts(CRLA.SNOTEL[3],frequency = 1)
CRLA.Tmaxts <- ts(CRLA.SNOTEL[4],frequency = 1)
CRLA.Tmints <- ts(CRLA.SNOTEL[5],frequency = 1)
CRLA.Tavgts <- ts(CRLA.SNOTEL[6],frequency = 1)
CRLA.PPTincts <- ts(CRLA.SNOTEL[7],frequency = 1)

CRLA.time=time(CRLA.SWEts)

library(lubridate)
library(zoo)
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(xts)
library(hydroTSM)


foo <- parse_date_time(CRLA.SNOTEL$Date, "m/d/y")

CRLA.Datezoo <- zoo(CRLA.SNOTEL[1],order.by = foo)
CRLA.SWEzoo <- zoo(CRLA.SNOTEL[2],order.by = foo)
CRLA.PPTacczoo <- zoo(CRLA.SNOTEL[3],order.by = foo)
CRLA.Tmaxzoo <- zoo(CRLA.SNOTEL[4],order.by = foo)
CRLA.Tminzoo <- zoo(CRLA.SNOTEL[5],order.by = foo)
CRLA.Tavgzoo <- zoo(CRLA.SNOTEL[6],order.by = foo)
CRLA.PPTinczoo <- zoo(CRLA.SNOTEL[7],order.by = foo)



## Yet another time series object type!
## Use xts() and bring the dates in from a string using as.Date()
CRLA.Date=as.Date(CRLA.SNOTEL$Date, "%m/%d/%Y")
# Do them individually
CRLA.Tmaxxts=xts(CRLA.SNOTEL$Tmax, order.by=CRLA.Date)
head(CRLA.Tmaxxts)
##            [,1]
## 2000-10-01   57
## 2000-10-02   59
## 2000-10-03   62
## 2000-10-04   61
## 2000-10-05   62
## 2000-10-06   65
# Do it as a matrix?
CRLA.xts=xts(CRLA.SNOTEL[,2:7], order.by=CRLA.Date)


# Sub-daily to annual ts
CRLA.Tmaxannual=daily2annual(CRLA.Tmaxxts, FUN=mean, na.rm=TRUE)
CRLA.Tmaxmonthly=daily2monthly(CRLA.Tmaxxts, FUN=mean, na.rm=TRUE)
plot(CRLA.Tmaxannual)

plot(CRLA.Tmaxmonthly)

# Do it as a matrix!
CRLA.annual=daily2annual(CRLA.xts, FUN=mean, na.rm=TRUE)
plot(CRLA.annual)

CRLA.monthly=daily2monthly(CRLA.xts, FUN=mean, na.rm=TRUE)
plot(CRLA.monthly)

## Let's look at PPTinc individually and use the sum function
CRLA.PPTincxts=xts(CRLA.SNOTEL$PPTinc, order.by=CRLA.Date)
CRLA.PPTincannual=daily2annual(CRLA.PPTincxts, FUN=sum, na.rm=TRUE)
CRLA.PPTincmonthly=daily2monthly(CRLA.PPTincxts, FUN=sum, na.rm=TRUE)
plot(CRLA.PPTincannual)

plot(CRLA.PPTincmonthly)

##

CRLA.Monthlyacf=acf(coredata(CRLA.monthly))

# Call variables individually below
CRLA.Tmaxacf=acf(coredata(CRLA.Tmaxmonthly))

# or
# Call variables through matrix CRLA.monthly
CRLA.Tminacf=acf(coredata(CRLA.monthly[,4]))

CRLA.Tavgacf=acf(coredata(CRLA.monthly[,5]))

# or
# using $ commands
CRLA.SWEacf=acf(coredata(CRLA.monthly$SWE))

CRLA.PPTincacf=acf(coredata(CRLA.monthly[,6]))

CRLA.PPTaccacf=acf(coredata(CRLA.monthly[,2]))

for (i in 1:6 ) {

hydroplot(CRLA.monthly[,i], FUN=mean, ylab=names(CRLA.monthly)[i])
}
## [Warning: 'x' is a monthly object, so 'pfreq' has been changed to 'ma']
## [Warning: 'x' is a monthly object, so 'pfreq' has been changed to 'ma']

## [Warning: 'x' is a monthly object, so 'pfreq' has been changed to 'ma']

## [Warning: 'x' is a monthly object, so 'pfreq' has been changed to 'ma']

## [Warning: 'x' is a monthly object, so 'pfreq' has been changed to 'ma']

## [Warning: 'x' is a monthly object, so 'pfreq' has been changed to 'ma']