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
Details
These functions are generic because they are based on the dim
function, which is generic.
Value
nrow | returns the first dimension of an array or
matrix. If there are no dimensions, it returns NULL. |
ncol | returns the second dimension of an array or
matrix. If there is no second dimension, it returns NULL. |
NROW | returns the first dimension of an array or
matrix. If there are no dimensions, it returns the length. |
NCOL | returns 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
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