################################################################################
#
#' Calculate handwashing indicators
#'
#' @param surveyData A data frame containing information to calculate handwashing
#' indicators
#' @return A data frame of handwashing indicators
#' @examples
#' # apply get_handwashing_vars to surveyDataBGD dataset
#' hygieneDF <- get_handwashing_vars(washdata::surveyDataBGD)
#'
#' @export
#'
#
################################################################################
get_handwashing_vars <- function(surveyData) {
## Check if handwashing facility at home data is available
if(exists("handwashingFacilityDF")) {
## jmpHand1
jmpHand1 <- ifelse(surveyData$san107 == "No handwashing station", 1, 0)
## jmpHand2
jmpHand2 <- ifelse(surveyData$san107 == "Handwashing station with water only", 1, 0)
## jmpHand3
jmpHand3 <- ifelse(surveyData$san107 == "Handwashing station with clean water and soap available", 1, 0)
} else {
jmpHand1 <- vector(mode = "numeric", length = nrow(surveyData))
jmpHand1[jmpHand1 == 0] <- NA
jmpHand2 <- vector(mode = "numeric", length = nrow(surveyData))
jmpHand2[jmpHand2 == 0] <- NA
jmpHand3 <- vector(mode = "numeric", length = nrow(surveyData))
jmpHand3[jmpHand3 == 0] <- NA
}
## Create handDF
## Concatenate handwashing indicators
handDF <- data.frame("uniqueID" = surveyData[ , "uniqueID"],
jmpHand1, jmpHand2, jmpHand3)
## Return output
return(handDF)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.