Learn R Programming

permute (version 0.10-0)

nobs-methods: Number of observations in a given object

Description

stats::nobs() is a generic function that returns the number of observations from a model. permute provides methods for several other types of R object.

Usage

# S3 method for numeric
nobs(object, ...)

# S3 method for integer nobs(object, ...)

# S3 method for matrix nobs(object, ...)

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

# S3 method for character nobs(object, ...)

# S3 method for factor nobs(object, ...)

Value

The numeric number of observations in object.

Arguments

object

A data frame or matrix, or a numeric, integer, character, or factor vector.

...

Arguments passed to other methods.

Author

Gavin Simpson

Details

These methods return the number of observations in numeric, integer, character, or factor vectors, matrices, and data frames.

Examples

Run this code
suppressWarnings(RNGversion("3.5.0"))
set.seed(1)
## numeric vector
len <- sample(1:10, 1)
v <- as.numeric(sample(1:100, len))
len
obs <- nobs(v)
isTRUE(all.equal(len, obs))

## integer
len <- sample(1L:10L, 1)
obs <- nobs(len)
isTRUE(all.equal(len, obs))

Run the code above in your browser using DataLab