R/asfactormodel.R

Defines functions asfactormodel

Documented in asfactormodel

# %$HeadURL: file:///srv/svn/sintro/pkg/sprof/R/asfactormodel.R $
# %$Id: asfactormodel.R 224 2013-08-26 19:55:39Z gsawitzki $
# %$Revision: 224 $
# %$Date: 2013-08-26 21:55:39 +0200 (Mon, 26 Aug 2013) $
# %$Author: gsawitzki $
# %$Name:$
#
# source('~/projects/rforge/sintro/pkg/sprof/R/asfactormodel.R', chdir = TRUE)
#
# setwd("")
#! To Do
#! clean up

asfactormodel <- function(x, factormodel) {

# for a factor, the labels of the levels are called levels, 
#	and the level indicators are called labels.	
	if (is.factor(factormodel)) {
		labels <- levels(factormodel)
		levels <- labels(factormodel)
		ordered <- is.ordered(factormodel)
	} else if  (is.character(factormodel)) {
		levels <- 1: length(factormodel)
		labels <- factormodel
		ordered = is.ordered(factormodel)
	} else stop("xfactor: factormodel is of unsupported type")
	
	if (is.list(x)) {
		sapply(x, 
			function(X){factor(unlist(X), 
				levels, 
				labels,
				ordered=ordered)}
			)
		} else {		
		factor(x, 
			levels, 
			labels,
			ordered=ordered)
	}
}

Try the sprof package in your browser

Any scripts or data that you put into this service are public.

sprof documentation built on May 31, 2017, 1:56 a.m.