Zum Hauptinhalt springen

154  filter-na3

Schlüsselwörter

Aufgaben, Statistik, Prognose, Modellierung, R, Datenanalyse, Regression

Filtern Sie alle Zeilen mit fehlende Werte im Datensatz penguins!

Liefern Sie die Spalten zurück, die fehlende Werte aufweisen.

154.0.1 Setup

library(tidyverse)
d_path <- "https://vincentarelbundock.github.io/Rdatasets/csv/palmerpenguins/penguins.csv"
d <- read_csv(d_path)
## Rows: 344 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): species, island, sex
## dbl (6): rownames, bill_length_mm, bill_depth_mm, flipper_length_mm, body_ma...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
nrow(d)
## [1] 344

154.0.2 Weg 1

d_na_only <-
  d %>% 
  filter(!complete.cases(.)) 

d_na_only %>% 
  names()
## [1] "rownames"          "species"           "island"           
## [4] "bill_length_mm"    "bill_depth_mm"     "flipper_length_mm"
## [7] "body_mass_g"       "sex"               "year"

154.0.3 Weg 2

d %>% 
  filter(if_any(everything(), ~ is.na(.))) %>% 
  names()
## [1] "rownames"          "species"           "island"           
## [4] "bill_length_mm"    "bill_depth_mm"     "flipper_length_mm"
## [7] "body_mass_g"       "sex"               "year"

Aufgabenname: filter-na3


Categories:

  • 2023
  • eda
  • na
  • string