Learn R Programming

gdata (version 2.7.1)

nobs: Compute the Number of Non-missing Observations

Description

Compute the number of non-missing observations. Special methods exist for data frames, and lm objects.

Usage

nobs(x, ...)
## S3 method for class 'default':
nobs(x, ...)
## S3 method for class 'data.frame':
nobs(x, ...)
## S3 method for class 'lm':
nobs(x, ...)

Arguments

x
Target Object
...
Optional parameters (currently ignored)

Value

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

Details

In the simplest case, this is really just wrapper code for sum(!is.na(x)).

See Also

is.na, length

Examples

Run this code
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)

Run the code above in your browser using DataLab