14 Functions
R comes with a large library of built-in functions. A handful cover most of the day-to-day work of summarizing a dataset — the rest of this book adds many more, but these are worth knowing cold.
14.1 sum() and length()
14.2 mean() and summary()
14.3 sqrt()
14.4 data.frame(), head(), and View()
data.frame() builds a table-like structure with named columns of possibly different types — the everyday format for a dataset. head() previews the first few rows without printing the whole thing; View() opens the data in a spreadsheet-style tab within RStudio.
View(field_data) would open this table in its own tab — this only works in a full RStudio session, not in the browser-based examples in this book.
Summary
| Concept | Description |
|---|---|
| Key Built-in Functions | |
| sum() and length() | Total a vector's values, and count how many values it has. |
| mean() and summary() | The average of a vector, and a quick min/quartile/median/mean/max overview. |
| sqrt() | The square root — recurs throughout descriptive statistics. |
| data.frame(), head(), and View() | Build a table of named columns; preview the first rows; open it in a spreadsheet-style viewer. |