The most important aspect to learn about R, and perhaps programming in general, is that tasks are completed sequentially. Large functions are objects built on small steps. Code is written into the script, run in the console, and plots are rendered on the right pane to visualize results.
The goal of this worksheet is begin enganging with R on basic levels, including computing arithmatic, saving objects, and subsetting vectors.
R can compute all commonly used arithmatic operations. The user inputs the parameters into a function, or specifies the relationship among objects, the result is returned in the console.
The most straightforward way to combine numbers, letters or logicals is in a vector. Vectors are created directly using the function c(). Vectors have positions, beginning at 1. To call a position, nameofvector[indexnumber]
Functions are the heart of R. They sourced files allow users to call code created and distributed within packages, or sent from friends! Functions have three essential parts.
The secret to R is a robust sense of adventure and confidence. There are tens of thousands of functions, in thousands of packages. One cannot expect to ever “know” R, this is simply the wrong mindset. Instead of focusing on memorizing the syntaxes, functions and design - place the following skill above all others: Reading the help screen
All published functions have help screens. They have a standardized format. At the top is a brief description explains the goal of the function.There may be a small paragraph on usage, especially in the function takes on multiple forms. The arguments are described next, each argument is described in a row, and should specify whether there is a default. All arguments without defaults are mandatory. This is followed by additional details, other sources, and citations. Finally the value section reports the format of the output. Most importantly, good help screens come with reproducible code examples at the very bottom. This code should run without any additional lines, thereby giving the user a good idea about the format of the code.