liveBook · Manning

Cbind() function

As explained in Statistics Slam Dunk

The cbind() function is a base R function that combines compatible vectors or objects column-wise.

cbind() is a base R function for combining compatible vectors or objects column-wise. It creates one wider data set while retaining the rows from the supplied objects. section 7.3

A practical workflow checks the component data sets before combining them:

  • Prepare separate objects with the required variables, such as road-team and home-team statistics. section 7.3 section 17.3
  • Use dim() to compare row and column counts. In the foul example, df3 has 1,312 rows and 6 columns, while df4 has 1,312 rows and 5 columns. section 7.3
  • Continue wrangling the combined object with functions such as as.factor(), as.Date(), mutate(), and select(). section 17.3

Combining road and home NBA odds

After preparing roadodds and homeodds with distinct variable names, combine them with: oddsdf2 <- cbind(roadodds, homeodds). Calling dim(oddsdf2) returns 1,230 rows and 14 columns, matching the 1,230-game regular-season schedule. The combined data can then support factor conversion, date conversion, and month-based variables.

Attaching predictions to observed wins

cbind() also attaches prediction output to observed values: cbind(fit2_pred, test) %>% mutate(wins_dif = abs(wins - fit)). The resulting table compares predicted wins, confidence limits, and actual wins, producing an average absolute difference of 9.94. section 5.7.7

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates executable combinations and dimension checks, but does not develop cbind() internals beyond horizontal joining.
Examples
Uses NBA foul, team-season statistics, betting odds, and predicted-versus-actual wins data.
What it assumes
Assumes prepared component objects and basic familiarity with selecting, renaming, and inspecting variables.
What you can do after
Apply it via base R to assemble wider data sets and prediction tables, then inspect their dimensions and continue analysis.
How it connects
Connects cbind() with data frames, dim(), select(), rename(), mutate(), as.factor(), as.Date(), and prediction evaluation.

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.