1+2
[1] 3
3/4
[1] 0.75
9*8
[1] 72
exp(4)
[1] 54.59815
August 22, 2023
If you are on a tablet or Chromebook, you can access R & RStudio via https://posit.cloud/ for free. However, they have limited computing resources. Be mindful of your experimentation. You may also be able to use Quarto in Rstudio cloud.
You can install R via their website: https://www.r-project.org/.
You can install RStudio for free from their website: https://posit.co/download/rstudio-desktop/
R can be used as a calculator; below are a few examples:
These types of data are stored as a number in R. They may be whole numbers or contains decimal values known as double.
This type of data is stored a string of character values. They are usually surrounded by quotes in the output.
This type of data indicates TRUE
or FALSE
data. It is binary data.
This indicates that a value is missing or not computed. Commonly stored as NA
or NaN
.
R has specialized functions that can compute specific values. R functions require inputs, known as arguments, to produce a specific output.
For example, the log()
function can be used to compute the natural logarithm of a specified input:
If you want to know information about a specific function, you can use the ?
operator:
which will open the help tab. Notice there are 2 arguments: x
and base
. This means that the log()
function can be extended to other base. To use common log1, specify the arguments:
Notice that I specified the arguments. You can also type this:
which produces the same results. This is because R uses positions in the function to determine argument values; therefore, if the positions are correct, you do not need to specify the argument name.
Going back to the First Lecture example, log(34)
, we did not specify the base. This is because functions have default values for arguments. The help documentation tells us what arguments have defaults and do not need to be specified.
You can extend the functionality of R. The tidyverse package includes a popular set of R packages for data wrangling and analysis. To install tidyverse, use the install.packages()
function2:
Once you installed the R package, you will need to load with every R session using the library()
function:
Lecture | Slides | Videos | Files |
---|---|---|---|
1 | Slides | NA | NA |
2 | Slides | NA | NA |