R/Yes_No_NA.R

Defines functions Replace_0_w_No_Function Replace_1_w_Yes_Function Replace_NA_w_Period_Function Replace_NA_w_Blank_Function Zero_is_NA_Function Yes_Function NA_Function NA_is_Zero_Function No_Function

Documented in NA_Function NA_is_Zero_Function No_Function Replace_0_w_No_Function Replace_1_w_Yes_Function Replace_NA_w_Blank_Function Replace_NA_w_Period_Function Yes_Function Zero_is_NA_Function

#' Replace 0 with "No".
#'
#' @param x Vector of data.
#'
#' @export

Replace_0_w_No_Function <- function(x){	
	x[which(x == 0)] <- "No"
	return(x)
}

#' Replace 1 with "Yes".
#'
#' @param x Vector of data.
#'
#' @export

Replace_1_w_Yes_Function <- function(x){	
	x[which(x == 1)] <- "Yes"
	return(x)
}

#' Replace NA with a ".".
#'
#' @param x Vector of data.
#' @description Replace NAs with no text so they are not printed on datasheets.
#'
#' @export

Replace_NA_w_Period_Function <- function(x){
	x[is.na(x) == "TRUE"] <- "."
	return(x)
}

#' Replace NA with "".
#'
#' @param x Vector of data.
#' @description Replace NAs with no text so they are not printed on datasheets.
#'
#' @export

Replace_NA_w_Blank_Function <- function(x){
	x[is.na(x) == "TRUE"] <- ""
	return(x)
}

#' Replace 0 with NA.
#'
#' @param x Vector of data.
#'
#' @export

Zero_is_NA_Function <- function(x){	
	x[which(x == 0)] <- NA
	return(x)
}

#' Standardize "Yes" values.
#'
#' @param x Vector of data.
#'
#' @export

Yes_Function <- function(x){	
	x[which(
		x == "Yes" | 
		x == "yes" |
		x == "y" |
		x == "Egg" | 
		x == "Larva" | 
		x == "Nymph"
	)] <- "1"
	return(x)
}

#' Replace values with NA.
#'
#' @param x Vector of data.
#' @examples
#' x = c(1,2,3,4," ", "Not Recorded")
#' NA_Function(x)
#'
#' @export

NA_Function <- function(x){	
	x[which(
		x == "Not Recorded" | 
		x == "not recorded" | 
		x == "Not recorded" | 
		x == "unknown" | 
		x == "Unknown" | 
		x == Inf |
		x == -Inf | 
		x == "NaN" | 
		x == NaN | 
		x == 999 | 
		x == 9999 |
		x == -9999 |
		x == "-999.9" |
		x == "9999" |
		x == " "
	)] <- NA
	return(x)
}

#' Change NA values to 0.
#'
#' @param x Vector of data.
#'
#' @export

NA_is_Zero_Function <- function(x){	
	x[which(is.na(x))] <- 0
	return(x)
}

#' Change "No" values to 0.
#'
#' @param x Vector of data.
#'
#' @export

No_Function <- function(x){	
	x[which(
		x == "None" | 
		x == "No" | 
		x == "no" | 
		x == "none" | 
		x == "Feeding evidence, but no insects"
	)] <- "0"
	return(x)
}
ksauby/dataproc documentation built on May 20, 2019, 7:02 p.m.