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
