My very first R document with KnitR , please be kind!
# week 3 data
setwd("C:\\Users\\Rich\\SkyDrive\\Documents\\Futurelearn\\")
# load libraries
# read the data
raw <- read.csv("AustralianWines.csv", header=TRUE)
# Trim to include the first 180 rows only. Not sure why the extra rows are included.
# you could take a future proofing appraoch to this, and write a loop to remove any row where the sum is 0.
# but I took the easy route.
trimmed <- raw[1:180,]
# not all columns are numeric, so fix that
trimmed <- sapply(trimmed[2:7], as.numeric )
trimmed <- data.frame(trimmed)
# create time series objects for each series
WineType <- colnames(trimmed)
# start a loop to create time series for the data
# gave up on this approach!
#for(i in 1:ncol(trimmed)) {
# paste(WineType[i],"TS") <- ts(trimmed[i], start(c(1980,1), end=c(1994,12), freq=12))
# }
TrainStart <- c(1980,1)
TrainEnd <- c(1994,10)
TrainFortified.ts <- ts(trimmed$Fortified, start=TrainStart, end = TrainEnd, freq=12)
TrainRed.ts <- ts(trimmed$Red, start=TrainStart, end = TrainEnd, freq=12)
TrainSparking.ts <- ts(trimmed$sparkling, start=TrainStart, end = TrainEnd, freq=12)
TrainRose.ts <- ts(trimmed$Rose, start=TrainStart, end = TrainEnd, freq=12)
TrainSweetWhite.ts <- ts(trimmed$Sweet.white , start=TrainStart, end = TrainEnd, freq=12)
TrainDryWhite.ts <- ts(trimmed$Dry.white , start=TrainStart, end = TrainEnd, freq=12)
library(imputeTS)
## Warning: package 'imputeTS' was built under R version 3.3.2
TrainRose.ts = na.interpolation(TrainRose.ts)
# Create the validation time periods
# This time I created variables for the time series partitions
valstart <- c(1994,11)
valend <- c(1994,12)
ValFortified.ts <- ts(trimmed$Fortified, start=valstart, end = valend , freq=12)
ValRed.ts <- ts(trimmed$Red, start=valstart, end = valend , freq=12)
ValSparking.ts <- ts(trimmed$sparkling, start=valstart, end = valend , freq=12)
ValRose.ts <- ts(trimmed$Rose, start=valstart, end = valend , freq=12)
ValSweetWhite.ts <- ts(trimmed$Sweet.white , start=valstart, end = valend , freq=12)
ValDryWhite.ts <- ts(trimmed$Dry.white , start=valstart, end = valend , freq=12)
{r pressure, echo=FALSE} #plot(pressure) #echo = FALSE parameter was added to the code chunk to #prevent printing of the R code that generated the plot.