Use dplyr's rename() to change column names without changing the associated data. Write the new name on the left and the existing name on the right, as in rename(teamR = TEAM). This is especially useful when similar road and home columns will later be combined. section 6.3.2 section 7.3
Give road and home columns distinct names
After filtering NBA games into road and home data sets, rename shared fields before joining them. Road columns become teamR, venueR, Q1R, and FR; home columns become teamH, venueH, Q1H, and FH. Keep dataset, ID, and date unchanged so left_join() can match corresponding games. section 6.3.2
road %>%
rename(dataset = DATASET, ID = GAME_ID, date = DATE,
teamR = TEAM, venueR = VENUE, Q1R = Q1, Q2R = Q2,
Q3R = Q3, Q4R = Q4, OT1R = OT1,
OT2R = OT2, OT3R = OT3, OT4R = OT4,
OT5R = OT5, FR = F, MINR = MIN) -> road
home %>%
rename(dataset = DATASET, ID = GAME_ID, date = DATE,
teamH = TEAM, venueH = VENUE, Q1H = Q1, Q2H = Q2,
Q3H = Q3, Q4H = Q4, OT1H = OT1,
OT2H = OT2, OT3H = OT3, OT4H = OT4,
OT5H = OT5, FH = F, MINH = MIN) -> home
Inspect the complete rename() calls for the road and home NBA data sets, including shared identifiers and side-specific score variables. section 6.3.2
