## Review and Troubleshooting:
# Can you find the error in this code?
a<-c(3,2,5,10,2,7,1)
b<-vector(length=length(a))
for (i in 1:length(a)){
if(a[i]>4) { b[i]<-i*3
else b[i]<-0
}
# Strategies for finding errors
###########################################
## Making functions in R
# Make a new working directory called Week2
# Set this as your working directory
dir.create("../Week2")
setwd("../Week2")
# Functions are useful to allow us to define a series of
# operations that we'd like to be able to do whenever
# we need to
# General Example:
SumSquares<-function(x,y){
x^2+y^2
}
# Example 2 - make a function to get S from the Curve Number:
SFromCNIn<-function(CN){
return(1000/CN-10)
}
S<-SFromCNIn(30)
S
# Problem 1:
# Can you make a function for the
# Curve Number Equation?
# Hint, you will need S, kIa and P as parameters
# Problem 2:
# Nash-Sutcliffe Efficiency is a useful way for hydrologists
# to determine how well a model functions.
# Using the definition of N-S Efficiency introduced in class
# (or if you miss class, you can find it on Wikipedia),
# create a function that will determine this parameter
# Now lets make a new R script that includes all of these
# functions on them. Call it UsefulFunctions.R
# We can run this script without even opening it!
source("UsefulFunctions.R")
## Homework for this week :
# Create a Thornthwaite-Mather function
# Then use it to determine the streamflow for Fall Creek
# Assume PET = 0 for the first and last day of the year, and 5 mm at
# the midpoint of the year, increasing/decreasing linearly
# You can start out assuming that the
# AWC = 5 cm
# SAT = 8 cm
# But you should calibrate these to maximize N-S Efficiency
# Please hand in the R script and your final hydrograph
# Due Thursday morning, Feb 9.