Learn R Programming

permute (version 0.8-4)

nobs-methods: Number of observations in a given object

Description

nobs is a generic function to return the number of observations from a model. shuffle provides a few methods for other types of data object in R.

Usage

## S3 method for class 'numeric':
nobs(object, \dots)

## S3 method for class 'integer': nobs(object, \dots)

## S3 method for class 'matrix': nobs(object, \dots)

## S3 method for class 'data.frame': nobs(object, \dots)

Arguments

object
a data frame or matrix, or a numeric or integer vector.
...
arguments to other methods.

Value

  • The (numeric) number of observations in object.

Details

Function nobs is a simple generic function to return the number of observations in a range of R model objects. Methods are provided to work with a variety of R objects.

Examples

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