`as.numeric()` converts compatible R objects to numeric values. It is useful when a column looks usable but is stored as logical values or character strings, and later counting, arithmetic, or visualization needs numbers. section 6.4.6 section 8.4
Turn game-result flags into counts
A result table stores six outcome columns as logical values. Applying `as.numeric()` changes `FALSE` to `0` and `TRUE` to `1`, so the rows containing `1` can be replaced with their corresponding game counts before reshaping the table. section 6.4.6
tbl21$HHH <- as.numeric(tbl21$HHH) tbl21$HRH <- as.numeric(tbl21$HRH) tbl21$RHH <- as.numeric(tbl21$RHH) tbl21$RRR <- as.numeric(tbl21$RRR) tbl21$RHR <- as.numeric(tbl21$RHR) tbl21$HRR <- as.numeric(tbl21$HRR)
This listing converts each logical outcome column individually, preparing the table for indexed count replacement and `pivot_longer()`. section 6.4.6
Extract seconds from play lengths
After extracting the final two characters of values such as `00:00:12`, convert the new character column with `as.numeric()`; the resulting values include `12`, `18`, and `0` seconds. section 8.4
The same step can prepare formatted points-per-game strings for later numeric standardization, or coerce probability and median vectors before multiplying them to calculate expected value. section 19.3.2 section 3.8
