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
