levels()
La función en R Language se usa para obtener o establecer los niveles de un factor.
Sintaxis: niveles (x)
Parámetros:
x: Objeto Factor
Ejemplo 1:
# R program to get levels of a factor # Creating a factor gender <- factor(c("female", "male", "male", "female")); gender # Calling levels() function # to get the levels levels(gender)
Producción:
[1] female male male female Levels: female male [1] "female" "male"
Ejemplo 2:
# R program to set levels of a factor # Creating a factor gender <- factor(c("female", "male", "male", "female")); gender # Calling levels() function # to set the levels levels(gender) <- c("abc", "def") gender
Producción:
[1] female male male female Levels: female male [1] abc def def abc Levels: abc def
Publicación traducida automáticamente
Artículo escrito por nidhi_biet y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA