liveBook · Manning

rowSums() function

As explained in Statistics Slam Dunk

The rowSums() function in R computes sums across columns for each row of a compatible numeric object.

rowSums() is a built-in R function that adds numeric variables across each row. It is useful when one row represents an NBA team and columns hold season-by-season salaries or wins. section 11.4.1

Summing salaries and wins

After selecting Charlotte’s salary and win columns, calculate several team-level measures with mutate(): rowSums(.[2:17]) gives total salaries, rowSums(.[18:33]) gives total wins, and dividing those results gives salary efficiency. Dividing total wins by 16 and rounding gives mean wins. section 11.4.1

How Statistics Slam Dunk covers it

How deep it goes
Defines row-wise numeric summation and demonstrates indexed columns, but does not examine implementation internals.
Examples
Uses NBA salary and regular-season win columns for the Charlotte Hornets, New Orleans Pelicans, and league.
What it assumes
Assumes familiarity with data frames, numeric columns, column positions, square-bracket indexing, and dplyr pipelines.
What you can do after
Apply it via base R and dplyr to create row-level totals, ratios, and averages from selected numeric columns.
How it connects
Connects rowSums() with colSums(), data-frame indexing, mutate(), select(), and rbind().

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.