The R Project SVN R

Rev

Rev 68948 | Rev 85704 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 75011
Line 1... Line 1...
1
% File src/library/base/man/nrow.Rd
1
% File src/library/base/man/nrow.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2007 R Core Team
3
% Copyright 1995-2018 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{nrow}
6
\name{nrow}
7
\title{The Number of Rows/Columns of an Array}
7
\title{The Number of Rows/Columns of an Array}
8
\usage{
8
\usage{
Line 14... Line 14...
14
\alias{nrow}
14
\alias{nrow}
15
\alias{NROW}
15
\alias{NROW}
16
\alias{ncol}
16
\alias{ncol}
17
\alias{NCOL}
17
\alias{NCOL}
18
\arguments{
18
\arguments{
19
  \item{x}{a vector, array or data frame}
19
  \item{x}{a vector, array, data frame, or \code{\link{NULL}}.}
20
}
20
}
21
\description{
21
\description{
22
  \code{nrow} and \code{ncol} return the number of rows or columns
22
  \code{nrow} and \code{ncol} return the number of rows or columns
23
  present in \code{x}.
23
  present in \code{x}.
24
  \code{NCOL} and \code{NROW} do the same treating a vector as
24
  \code{NCOL} and \code{NROW} do the same treating a vector as
25
  1-column matrix.
25
  1-column matrix, even a 0-length vector, compatibly with
-
 
26
  \code{\link{as.matrix}()} or \code{\link{cbind}()}, see the example.
26
}
27
}
27
\references{
28
\references{
28
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
29
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
29
  \emph{The New S Language}.
30
  \emph{The New S Language}.
30
  Wadsworth & Brooks/Cole (\code{ncol} and \code{nrow}.)
31
  Wadsworth & Brooks/Cole (\code{ncol} and \code{nrow}.)
31
}
32
}
32
\seealso{
33
\seealso{
33
  \code{\link{dim}} which returns \emph{all} dimensions;
34
  \code{\link{dim}} which returns \emph{all} dimensions;
34
  \code{\link{array}}, \code{\link{matrix}}.
35
  \code{\link{array}}, \code{\link{matrix}}.
35
}
36
}
36
\value{an \code{\link{integer}} of length 1 or \code{\link{NULL}}.}
37
\value{an \code{\link{integer}} of length 1 or \code{\link{NULL}}, the
-
 
38
  latter only for \code{ncol} and \code{nrow}.}
37
\examples{
39
\examples{
38
ma <- matrix(1:12, 3, 4)
40
ma <- matrix(1:12, 3, 4)
39
nrow(ma)   # 3
41
nrow(ma)   # 3
40
ncol(ma)   # 4
42
ncol(ma)   # 4
41
 
43
 
42
ncol(array(1:24, dim = 2:4)) # 3, the second dimension
44
ncol(array(1:24, dim = 2:4)) # 3, the second dimension
43
NCOL(1:12) # 1
45
NCOL(1:12) # 1
44
NROW(1:12) # 12
46
NROW(1:12) # 12
-
 
47
 
-
 
48
## as.matrix() produces 1-column matrices from 0-length vectors,
-
 
49
## and so does cbind() :
-
 
50
dim(as.matrix(numeric())) # 0 1
-
 
51
dim(    cbind(numeric())) # ditto
-
 
52
## consequently, NCOL(.) gives 1, too :
-
 
53
NCOL(numeric()) # 1 and hence
-
 
54
NCOL(NULL)      # 1
45
}
55
}
46
\keyword{array}
56
\keyword{array}