####################################################################
# Author: Daniel Reed (daniel@danielreed.org)
# Purpose: Helper functions for data wrangling
# Date: Tue Sep 04 10:35:57 2018
####################################################################
#' Remove all attributes except class.
#'
#' @param vec A data frame column or vector
#' @return Return \code{vec} with no attributes except \code{class}
#' @export
strip <- function(vec){
# Attribute names
att_names <- names(attributes(vec))
# Remove class from list of attribute names
att_names <- att_names[att_names != "class"]
# Check that there are attributes; if not return original vector
if(length(att_names) == 0)return(vec)
# Loop through attributes and remove
for(i in att_names){
attr(vec, i) <- NULL
}
# Return vector
vec
}
#' Not in operator. Negated \code{%in%}.
#'
#' @usage x %!in% y
#' @param x Vector
#' @param y Vector
#' @title Not in operator
#' @export
`%!in%` <- Negate("%in%")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.