nobs: Compute the Number of Non-missing Observations

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/nobs.R

Description

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

Usage

1
2
3
4
5
6
7
nobs(object, ...)
## Default S3 method:
nobs(object, ...)
## S3 method for class 'data.frame'
nobs(object, ...)
## S3 method for class 'lm'
nobs(object, ...)

Arguments

object

Target Object

...

Optional parameters (currently ignored)

Details

Calculate the number of observations in object.

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.

Value

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 stats now provides a S3 dispatch function for 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 (nobs) function and method for "lm" objects (nobs.lm) are, as of gdata version 2.10.1, simply aliases for the equivalent functions in the base R stats package.

Since gdata's default method (nobs.default) processes vectors and hands any other data/object types to stats:::nobs.default.

Author(s)

Gregory R. Warnes [email protected]

See Also

is.na, length

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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)

Example output

sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

The following object is masked from 'package:stats':

    nobs

The following object is masked from 'package:utils':

    object.size

The following object is masked from 'package:base':

    startsWith

[1] 9
[1] 7
 x  y 
98 99 
[1] 98

gdata documentation built on June 6, 2017, 5:04 p.m.