#' calculate cominbe weight
#'
#' @param data data
#' @param yr2 weight for 2 years
#' @param yr4 weight for 4 years: 1999-2000 and 2001-2002
#' @param wtname name for combine weight column
#'
#' @return combine weight
#' @export
#'
nhs_wt <- function(data,yr2,yr4,wtname='cwt'){
(cycle <- length(unique(data$Year)))
if (missing(yr4)){
cwt <- data[,yr2]*1/cycle
eval(parse(text=sprintf('data$%s <- cwt',wtname)))
}else{
ck <- data$Year %in% prepare_years(1999:2001)
cwt <- ifelse(ck,data[,yr4]*2/cycle,data[,yr2]*1/cycle)
eval(parse(text=sprintf('data$%s <- cwt',wtname)))
}
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.