xnaref <- function(x){
if(is.factor(x))
if(!is.na(levels(x)[1]))
x <- factor(x,levels=c(NA,levels(x)),exclude=NULL)
return(x) }
#' naref
#'
#' make missing (NA) the reference level of a factor
#' @param DF the data frame to set with the default NA reference level
#' @keywords na naref reference factor
#' @export
#' @examples
#' naref(DF)
naref <- function(DF){
if(is.null(dim(DF))) return(xnaref(DF))
if(!is.data.frame(DF))
stop("You need to give me a data.frame or a factor")
DF <- lapply(DF, xnaref)
return(as.data.frame(DF))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.