liveBook · Manning

Data.frame() function

As explained in Statistics Slam Dunk

The data.frame() function in base R constructs a data frame from supplied vectors or other compatible column-like objects.

The base R data.frame() function constructs a data frame from supplied vectors or other compatible column-like objects. It is useful when a small analytical dataset must be created directly. section 6.4.5

Build a data frame by supplying named columns with matching observations:

  • Create a four-row quarter summary with character labels and numeric percentages: df1 <- data.frame(quarter = c("1Q", "2Q", "3Q", "4Q"), win_pct = c(70.89, 72.81, 75.12, 71.01)). section 6.4.5
  • Create a postseason dataset with a factor season column and numeric points-scored and points-allowed columns, then combine it with another object using rbind(). section 14.7

From summary to visualization

After constructing df1, use ggplot2 to map quarter to the x-axis and win_pct to the y-axis, producing a bar chart that highlights winning percentages by quarter.

Prepare paired NBA data

Construct df2 for championship teams’ postseason averages, combine it with regular-season data using rbind(), and add a Season label before calling ggpaired(). section 14.7

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates named columns, character, numeric, and factor vectors, then stops short of broader automation for larger datasets.
Examples
Uses quarter winning percentages and championship-team scoring and defensive averages as concrete data-frame examples.
What it assumes
Assumes familiarity with vectors and basic R assignment while demonstrating data preparation from supplied values.
What you can do after
Builds small data frames from scratch and prepares them for tables, charts, row binding, and paired comparisons.
How it connects
Connects data frames with vectors, tibbles, rbind(), dplyr, ggplot2, and paired boxplots.

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.