liveBook · Manning

Na.omit() function

As explained in Statistics Slam Dunk

The base R na.omit() function returns an object with observations containing missing values removed.

Use na.omit() to remove observations containing missing values before analysis. It returns a cleaned object while leaving the original data set unchanged when applied to a temporary subset. section 10.4.2

A practical missing-data workflow is:

  • Select only the variables needed for the next plot or calculation. section 10.4.2
  • Assign the subset to a temporary object, then call na.omit() on that object. section 10.4.2
  • Pass the resulting complete observations to plotting, correlation, or summary functions. section 10.4.1 section 10.4.3

Prepare NBA payroll data for a plot

Create a focused data frame and remove incomplete rows without altering salaries: salaries2000 <- select(salaries, Team, s2000, pc2000); salaries2000 <- na.omit(salaries2000). The cleaned object can then support a payroll dot plot grouped by playoff outcome. section 10.4.2

salaries2000 <- select(salaries, Team, s2000, pc2000)
salaries2000 <- na.omit(salaries2000)

dot1 <- ggplot(salaries2000) +
 geom_point(aes(x = s2000, y = reorder(Team, s2000), 
                color = factor(pc2000)), size = 3) +
 labs(title= "NBA Team Payrolls (USD)", 
      subtitle = "1999-2000", 
      x = "Team Payroll", 
      y = "") +
 scale_x_continuous(labels = label_dollar(scale_cut = cut_short_scale())) +
 theme(plot.title = element_text(face = "bold")) + 
 scale_color_manual(name = "", 
                    labels = c("No playoffs", 
                               "Made playoffs", 
                               "Won title"), 
                    values = c("0" = "navy", 
                               "10" = "gold3", 
                               "11" = "red")) +
 theme(legend.position = "bottom") +
 theme(axis.text.x = element_text(angle = 45, hjust = 1))

Browse the complete R listing for selecting columns, removing missing rows, and building the 1999–2000 payroll visualization. section 10.4.2

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates the function in temporary subsets and larger summary workflows, but does not explain its internal implementation.
Examples
Uses NBA salary, wins, playoff-classification, payroll dot-plot, correlation-plot, and inflation-adjusted summary data.
What it assumes
Assumes familiarity with data frames and select(); teaches the temporary-subset pattern for handling missing observations.
What you can do after
Apply it via base R to create complete temporary analysis data without permanently deleting rows from the original data set.
How it connects
Connects missing values with data-frame subsetting, correlation analysis, visualization, and grouped summaries.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.