ID EN
Miscellaneous

droplevels

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Fungsi droplevels digunakan untuk menghapus level yang tidak terpakai dari suatu faktor atau, lebih umum, dari faktor-faktor dalam bingkai data.

Syntax

R
# S3 method for factor
droplevels(x, exclude = if(anyNA(levels(x))) NULL else NA, …)
# S3 method for data.frame
droplevels(x, except, exclude, …)

Arguments

Parameter Deskripsi
x an object from which to drop unused factor levels.
exclude passed to factor(); factor levels which should be excluded from the result even if present. Note that this was implicitly NA in R <= 3.3.1 which did drop NA levels even when present in x, contrary to the documentation. The current default is compatible with x[ , drop=TRUE].
&#8230; further arguments passed to methods
except indices of columns from which not to drop levels

Return Value

droplevels mengembalikan objek dari kelas yang sama dengan x

Details

Metode untuk kelas "faktor" saat ini setara dengan faktor(x, kecualikan=kecualikan). Untuk metode bingkai data, Anda sebaiknya jarang menentukan pengecualian “secara global” untuk semua kolom faktor; melainkan defaultnya menggunakan pengecualian khusus faktor yang sama dengan metode faktor itu sendiri. Argumen kecuali mengikuti aturan pengindeksan biasa.

Contoh

Example
R
# NOT RUN {
aq <- transform(airquality, Month = factor(Month, labels = month.abb[5:9]))
aq <- subset(aq, Month != "Jul")
table(           aq $Month)
table(droplevels(aq)$Month)
# }

See Also

subset for subsetting data frames. factor for definition of factors. drop for dropping array dimensions. drop1 for dropping terms from a model. [.factor for subsetting of factors.