#### General data wrangling helper functions #####
#' Inverse of 'in' function call
#' @param a Condition 1
#' @param b Condition 2
#' @export
#' @author Martin Jung
#' @examples
#' \donttest{
#' x = c('A','B','D')
#' y = c('A','C','D')
#' x %notin% y
#'}
`%notin%` = function(a, b){!(a %in% b)}
#' Normalize a vector by minimum and maximum
#'
#' @param x # Input vector
#' @param na.rm # NA values to be removed
#' @export
#' @author Martin Jung
#' @return A normalized layer
#' @examples
#' \donttest{
#' normalize(trees$Volume)
#' }
normalize <- function(x, na.rm = TRUE)
{
if (length(x) == 1)
return(1)
y <- suppressWarnings((x - min(x, na.rm = na.rm))/(max(x,
na.rm = na.rm) - min(x, na.rm = na.rm)))
if (any(is.nan(y)))
return(x)
else return(y)
}
#' Show difference between two vectors
#'
#'
#' and the elements of y that are not in x (not the same thing...)
#' @param x vector x
#' @param y vector y
#' @return returns a list of the elements of x that are not in y and vice versa
#' @keywords difference
#' @export
#' @usage setdiff2(x,y)
#' @author Martin Jung
setdiff2 <- function(x,y) {
Xdiff = setdiff(x,y)
Ydiff = setdiff(y,x)
list(X_not_in_Y=Xdiff, Y_not_in_X=Ydiff)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.