gdata (version 2.18.0)

nobs: Compute the Number of Non-missing Observations

Description

Compute the number of non-missing observations. Provides a 'default' method to handle vectors, and a method for data frames.

Usage

nobs(object, ...)
# S3 method for default
nobs(object, ...)
# S3 method for data.frame
nobs(object, ...)
# S3 method for lm
nobs(object, ...)

Arguments

object

Target Object

Optional parameters (currently ignored)

Value

Either single numeric value (for vectors) or a vector of numeric values (for data.frames) giving the number of non-missing values.

Details

Calculate the number of observations in object.

  • For numeric vectors, this is simply the number of non-NA elements, as computed by sum(!is.na(object)).

  • For dataframe objects, the result is a vector containing the number of non-NA elementes of each column.

The nobs and nobs.lm functions defined in gtools are simply aliases for the functions in the base R stats package, provided for backwards compatibility.

See Also

is.na, length

Examples

Run this code
# NOT RUN {
x <- c(1,2,3,5,NA,6,7,1,NA )
length(x)
nobs(x)

df <- data.frame(x=rnorm(100), y=rnorm(100))
df[1,1] <- NA
df[1,2] <- NA
df[2,1] <- NA

nobs(df)

fit <- lm(y ~ x, data=df)
nobs(fit)
# }

Run the code above in your browser using DataLab