[R-gregmisc-users] SF.net SVN: r-gregmisc:[1546] trunk/gdata
Brought to you by:
warnes
From: <wa...@us...> - 2012-06-06 20:26:12
|
Revision: 1546 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1546&view=rev Author: warnes Date: 2012-06-06 20:26:01 +0000 (Wed, 06 Jun 2012) Log Message: ----------- Define aliases for 'nobs' and 'nobs.lm' to support backward compatibility for packages depending on gdata. Modified Paths: -------------- trunk/gdata/NAMESPACE trunk/gdata/R/nobs.R trunk/gdata/man/nobs.Rd Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2012-06-06 01:59:09 UTC (rev 1545) +++ trunk/gdata/NAMESPACE 2012-06-06 20:26:01 UTC (rev 1546) @@ -22,7 +22,7 @@ lowerTriangle, "lowerTriangle<-", matchcols, - #nobs, # default method now provided by stats package + nobs, # default method now provided by stats package nPairs, read.xls, rename.vars, @@ -123,7 +123,7 @@ ## nobs stuff S3method(nobs, data.frame) S3method(nobs, default) -##S3method(nobs, lm) # now provided by stats package +S3method(nobs, lm) # now provided by stats package ## Object size stuff S3method(print, object_size) Modified: trunk/gdata/R/nobs.R =================================================================== --- trunk/gdata/R/nobs.R 2012-06-06 01:59:09 UTC (rev 1545) +++ trunk/gdata/R/nobs.R 2012-06-06 20:26:01 UTC (rev 1546) @@ -1,14 +1,22 @@ # $Id$ -## Now provided by 'stats' package -## nobs <- function(x,...) -## UseMethod("nobs",x) +## Now provided by 'stats' package, provide aliase here to satisfy +## dependencies +nobs <- stats::nobs -nobs.default <- function(object, ...) sum( !is.na(object) ) +nobs.default <- function(object, ...) + { + if(is.vector(object)) + sum( !is.na(object) ) + else + stats::nobs.default(object, ...) + } + nobs.data.frame <- function(object, ...) sapply(object, nobs.default) -## Now provided by the 'stats' package -## nobs.lm <- function(x, ...) -## nobs.default(x$residuals) +## Now provided by 'stats' package, provide 'alias' to satisfy +## dependencies +nobs.lm <- stats:::nobs.lm + Modified: trunk/gdata/man/nobs.Rd =================================================================== --- trunk/gdata/man/nobs.Rd 2012-06-06 01:59:09 UTC (rev 1545) +++ trunk/gdata/man/nobs.Rd 2012-06-06 20:26:01 UTC (rev 1546) @@ -28,42 +28,65 @@ % \name{nobs} -%% \alias{nobs} % Now provided by stats +\alias{nobs} % Now provided by stats \alias{nobs.data.frame} \alias{nobs.default} -%% \alias{nobs.lm} % Now provided by stats +\alias{nobs.lm} % Now provided by stats %- Also NEED an `\alias' for EACH other topic documented here. \title{ Compute the Number of Non-missing Observations } \description{ - Compute the number of non-missing observations. New 'default' method, - and method for data frames. + Compute the number of non-missing observations. Provides a 'default' + method to handle vectors, and a method for data frames. } \usage{ -%% nobs(object, ...) +nobs(object, ...) \method{nobs}{default}(object, ...) \method{nobs}{data.frame}(object, ...) -%% \method{nobs}{lm}(object, ...) +\method{nobs}{lm}(object, ...) } \arguments{ \item{object}{ Target Object } \item{\dots}{ Optional parameters (currently ignored)} } \details{ + Calculate the number of observations in \code{object}. - In the simplest case, this is really just wrapper code for - \code{sum(!is.na(object))}. - + \itemize{ + \item{For numeric vectors, this is simply the number of non-NA elements, as computed by + \code{sum(!is.na(object))}. } + \item{For dataframe objects, the result is a vector containing the + number of non-NA elementes of each column. } + } + + The \code{nobs} and \code{nobs.lm} functions defined in gtools are + simply aliases for the functions in the base R \code{stats} package, + provided for backwards compatibility. } \value{ - A single numeric value or a vector of values (for data.frames) giving - the number of non-missing values. + Either single numeric value (for vectors) or a vector of numeric + values (for data.frames) giving the number of non-missing values. } +\note{ + The base R package \code{stats} now provides a S3 dispatch function for + \code{nobs}, and methods for for objects of classes ‘"lm"’, ‘"glm"’, + ‘"nls"’ and ‘"logLik", as well as a default method. + + Since they provided a subset of the the functionality, the base + method dispatch (\code{nobs}) function and method for "lm" objects + (\code{nobs.lm}) are, as of \code{gdata} version 2.10.1, simply + aliases for the equivalent functions in the base R \code{stats} + package. + + Since \code{gdata}'s default method (\code{nobs.default}) processes + vectors and hands any other data/object types to + \code{stats:::nobs.default}. +} + \author{ Gregory R. Warnes \email{gr...@wa...} } \seealso{ \code{\link{is.na}}, \code{\link{length}} } \examples{ - x <- c(1,2,3,5,NA,6,7,1,NA ) length(x) nobs(x) @@ -74,5 +97,8 @@ df[2,1] <- NA nobs(df) + +fit <- lm(y ~ x, data=df) +nobs(fit) } \keyword{attribute} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |