Week 3: Manipulating Data with Vectors & Matrices
Learn indexing, slicing, recycling, and introduce matrices and R's help system.
Explore Chapter 3Getting Help in R.
As you learn R, knowing how to find help is essential. R has excellent built-in documentation and functions to assist you.
- `help(function_name)` or `?function_name`: The most common way to get help. This displays the documentation page for a specific function or topic if you know its name.
help(mean) ?matrix ?cThe help page typically includes a description, usage details, argument explanations, examples, and related functions.
- `help.search("keyword")` or `??keyword`: Searches the documentation for a keyword or concept when you don't know the exact function name. Requires quotes for multi-word searches.
help.search("standard deviation") ??"linear model"This returns a list of potentially relevant help pages.
- `example(function_name)`: Runs the example code provided in the help documentation for a specific function. This is a great way to see the function in action.
example(mean) example(plot) - `str(object_name)`: Displays the structure of an R object (like a vector, matrix, data frame, or list), showing its type, dimensions, and a preview of its contents. Very useful for understanding complex objects.
my_vec <- c("a", "b", "c") str(my_vec) # Output: chr [1:3] "a" "b" "c" my_mat <- matrix(1:4, nrow=2) str(my_mat) # Output: int [1:2, 1:2] 1 2 3 4
Don't hesitate to use these help functions frequently! They are invaluable tools for learning and troubleshooting in R.