R/naref.R

Defines functions xnaref naref

Documented in naref

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))
}
jakewalker56/jml documentation built on May 18, 2019, 9:08 a.m.