nrow
Get the Number of Rows or Columns of an Array or Matrix

Description

Returns the number of rows or columns of an array or matrix.

Usage

nrow(x)
NROW(x)
ncol(x)
NCOL(x)

Arguments

x any object.

Details

These functions are generic because they are based on the dim function, which is generic.
Value
nrowreturns the first dimension of an array or matrix. If there are no dimensions, it returns NULL.
ncolreturns the second dimension of an array or matrix. If there is no second dimension, it returns NULL.
NROWreturns the first dimension of an array or matrix. If there are no dimensions, it returns the length.
NCOLreturns the second dimension of an array or matrix. If there is no second dimension, it returns 1.
References
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software. (ncol and nrow.)
See Also
dim, length, array, data.frame
Examples
m <- matrix(1:6, 3, 2)
nrow(m) # 3
NROW(m) # 3
ncol(m) # 2
NCOL(m) # 2
nrow(1:4) # NULL
NROW(1:4) # 4
ncol(1:4) # NULL
NCOL(1:4) # 1
Package base version 6.1.1-7
Package Index