filter()
La función en R Language se usa para elegir casos y filtrar los valores en función de la expresión de filtrado.
Sintaxis: filtro (x, expr)
Parámetros:
x: Objeto a filtrar
expr: expresión como base para el filtrado
Ejemplo 1:
# R Program to filter cases # Loading library library(dplyr) # Create a data frame with missing data d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "yes", "no", "no") ) d # Finding rows with NA value filter(d, is.na(ht)) # Finding rows with no NA value filter(d, ! is.na(ht))
Producción:
name age ht school 1 Abhi 7 46 yes 2 Bhavesh 5 NA yes 3 Chaman 9 NA no 4 Dimri 16 69 no name age ht school 1 Bhavesh 5 NA yes 2 Chaman 9 NA no name age ht school 1 Abhi 7 46 yes 2 Dimri 16 69 no
Ejemplo 2:
# R Program to filter cases # Loading library library(dplyr) # Create a data frame d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"), age = c(7, 5, 9, 16), ht = c(46, NA, NA, 69), school = c("yes", "no", "yes", "no") ) d # Finding rows with school filter(d, school == "yes") # Finding rows with no school filter(d, school == "no")
Producción:
name age ht school 1 Abhi 7 46 yes 2 Bhavesh 5 NA no 3 Chaman 9 NA yes 4 Dimri 16 69 no name age ht school 1 Abhi 7 46 yes 2 Chaman 9 NA yes name age ht school 1 Bhavesh 5 NA no 2 Dimri 16 69 no
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