R/subset.smooth.R

#' @method `[` smooth
#' @export
"[.smooth" <-
function(x, ..., drop = FALSE)
{
	cl <- oldClass(x)
	oldClass(x) <- NULL
	ats <- attributes(x)
	ats$dimnames <- NULL
	ats$dim <- NULL
	ats$names <- NULL
	y <- x[..., drop = drop]
	if(!is.null(nas <- ats$NAs)) {
		if(is.null(d <- dim(x)))
			d <- c(length(x), 1)
		navec <- array(logical(d[1]), d)
		navec[nas,  ] <- TRUE
		navec <- navec[...]
		nas <- if(is.null(dim(navec))) navec else navec[, 1]
		nas <- seq(nas)[nas]
		if(length(nas))ats$NAs <- nas else ats$NAs=NULL
	}
	attributes(y) <- c(attributes(y), ats)
	oldClass(y) <- cl
	y
}

Try the gam package in your browser

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

gam documentation built on March 31, 2023, 9:10 p.m.