R/onebasis.R

Defines functions onebasis

Documented in onebasis

###
### R routines for the R package dlnm (c)
#
onebasis <-
function(x, fun="ns", ...) {
#
################################################################################
#
  nx <- names(x)
  x <- as.vector(x)
  range <- range(x,na.rm=TRUE)
  args <- list(...)
  args$x <- x
  cen <- args$cen
#
  # CHECK THE CONTENT AND OPTIONALLY MODIFY OBJECTS THROUGH assign
  checkonebasis(fun,args,cen)
#
###########################################################################
# TRANSFORMATION
#
  # CREATE THE BASIS
  basis <- do.call(fun,args)
  # FORCE TO BE A MATRIX (NOT WITH as.matrix AS IT DELETES ATTRIBUTES)
  if(is.null(dim(basis))) dim(basis) <- c(length(x),1)
  attr <- attributes(basis)
#
##########################################################################
#
  # NAMES AND ATTRIBUTES (KEEP cen IF PROVIDED, TO BE USED LATER FOR CENTERING)
  attributes(basis) <- c(list(fun=fun), attr, list(range=range,cen=cen))
  dimnames(basis) <- list(nx, paste("b",seq(ncol(basis)),sep=""))
#
  class(basis) <- c("onebasis","matrix")
#
  return(basis)
}

Try the dlnm package in your browser

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

dlnm documentation built on Oct. 7, 2021, 5:09 p.m.