ID EN
Data Frame & Matrix

nrow

R Base 3.6.2 🇮🇩 Bahasa Indonesia

nrow dan ncol mengembalikan jumlah baris atau kolom yang ada di x. NCOL dan NROW melakukan hal yang sama dengan memperlakukan vektor sebagai matriks 1 kolom, bahkan vektor dengan panjang 0, kompatibel dengan as.matrix() atau cbind(), lihat contohnya.

Syntax

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

Arguments

Parameter Deskripsi
x a vector, array, data frame, or NULL.

Return Value

bilangan bulat dengan panjang 1 atau NULL, yang terakhir hanya untuk ncol dan nrow.

Contoh

Example
R
# NOT RUN {
ma <- matrix(1:12, 3, 4)
nrow(ma)   # 3
ncol(ma)   # 4

ncol(array(1:24, dim = 2:4)) # 3, the second dimension
NCOL(1:12) # 1
NROW(1:12) # 12

## as.matrix() produces 1-column matrices from 0-length vectors,
## and so does cbind() :
dim(as.matrix(numeric())) # 0 1
dim(    cbind(numeric())) # ditto
## consequently, NCOL(.) gives 1, too :
NCOL(numeric()) # 1 and hence
NCOL(NULL)      # 1
# }

See Also

dim which returns all dimensions; array matrix.