knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(HW5262)
library(tidyverse)

.Examples

Testing drought function code and function

# example data
temp_data =
    data.frame(
      Date = c(1895:2019),
      Value = sample(1:1, 125, replace = T)
    )

head(temp_data, 10)

# tells you whether there was a drought in the specified year given inputed drought index and threshold value
calc_if_drought(temp_data, 2, 1, 2000)

. Extreme precipiation anomalies

# preloaded data
data("rain")
calc_extreme_rain_anom(rain)

. Extreme temperature anomalies

# example data
temp_test_data =
    data.frame(
        Date = c(1:4),
        Value = c(1:4),
        Anomaly = c(1:4)
    )
temp_test_data

calc_extreme_temp_anom(temp_test_data)

. Crop Harvest

#create some fake climate data
#springtime mean temperatures by date and location
crop_temp = rnorm(500, mean = 16 , sd = 2)
dates = seq(from = 1920, to = 2010, by = 10)
locations = c("SB", "LA", "SF","SLO","SD")

ca_temp <- matrix(crop_temp, nrow = 10, ncol = 5, dimnames = list(c(dates), c(locations)))

#what example dataframe would look like 
ca_temp

# function output: 
calc_crop_harvest(ca_temp, 15, .5)

. Crop cost

# example dataset
crop_rain = rnorm(500, mean = 10 , sd = 4)
dates = seq(from = 1920, to = 2010, by = 10)
locations = c("SB", "LA", "SF","SLO","SD")

ca_rain <- matrix(crop_rain, nrow = 10, ncol = 5,
                       dimnames = list(c(dates), c(locations)))
# example of what data looks like
ca_rain

#function output
calc_crop_cost(ca_rain, 10, .5, 1000, 1.50)


annaclairemarley/HW5262 documentation built on April 5, 2020, 8:59 p.m.