knitr::opts_chunk$set(echo = FALSE) library(DiagrammeR) library(knitr) library(kableExtra)
You can leave feedback on the discussion board on Toledo.
When you have questions you can send an email to:
But first try to answer your own questions through Google.
For the exercise portion of this course, there is permanent evaluation.
{height=500px}
R is a programming language used for data analysis and visualization. To use R effectively, we need to know about:
We will be using Rstudio to communicate with R.
{#id .class width=200, height=100px}
{#id .class width=500 height=100px}
You should already have downloaded and installed both R and Rstudio. You need both to follow the exercises. The only program you will ever need to launch is Rstudio.
When you open Rstudio, go to "File - New File - R Script" to create a new Script. This is your working document. Under your script you will see the Console. This is your dialogue with R.
If you type something in the Console and press "Enter", it will be run. If you write something in your script, select the part you want to run and press "Ctrl" + "Enter", that part will appear in your console and will be run.
Any objects R has stored appear in your Global Environment.
A .R document is just a .txt document that is associated with R. A #
let's R know the line is a comment and should be ignored.
# These are comments to make clear what is happening # Here I wil put input in a function and assign the output to the "result" object result <- function(input, option = "setting")
{height=350px}
a <- 1
In R values are assigned using <-
. A shortcut for these two symbols in Rstudio is Alt
+ -
.
a
is now saved as an object and is assigned the value 1. If you ask R for the object a
, it will return its value.
a
data <- cars
{height=350px}
The building blocks for objects are:
"Hello"
, "a"
3.14
, 1
1L
, 214L
TRUE
or FALSE
, T
or F
)1 + 4i
Special values:
Inf
- InfinityNA
- Not availableNaN
- Not a NumberThese data types can be used on their own, or arranged in data structures:
Always of the form function(arguments, ...)
Linear regression model for the relationship between yield and spacing for apple trees:
lm(yield ~ spacing, data = apples)
lm()
is the function with yield, spacing and apples being the inputs.
BUT how do you know this?
Try:
?lm()
{height=500px}
The power of R lies in its packages. They are collections of functions written by other people.
You download packages to your computer using install.packages()
. Your R session can only use the package after you load it to your library using library()
.
install.packages("dplyr") library(dplyr)
You can always use "?" to get more information on the package.
?dplyr
Vignettes are longer form documentation and tutorials. See which are available:
vignette(package = "dplyr")
Open the one you want using the title.
vignette("dplyr", package = "dplyr")
Good sources: r-bloggers.com, stackoverflow.com, ...
# Package you need to install a github package if(!require("devtools")) install.packages("devtools"); library("devtools") # Make sure edcpR is not in use before installing unloadNamespace("edcpR") # Install/update course package install_github("https://github.com/wardfont/edcpR", build_vignettes = T, force = T) # Load package library(edcpR)
Deadline: Next week Wednesday at 12:00
No submission is Zero for the assignment.
You will be graded on:
Intro to R
Troubleshooting
Etiquette
Data visualisation
Data visualisation 2
R Style guide
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.