knitr::opts_chunk$set(echo = FALSE)
library(DiagrammeR)
library(knitr)
library(kableExtra)

Contact

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.

EDCP exercises

Evaluation

For the exercise portion of this course, there is permanent evaluation.

Why use R

{height=500px}

R

R is a programming language used for data analysis and visualization. To use R effectively, we need to know about:

R

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.

Rstudio Components

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.

Scripts

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")

Structure of R

{height=350px}

Objects

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

A bigger object

data <- cars

{height=350px}

Data types

The building blocks for objects are:

Special values:

Data structures

These data types can be used on their own, or arranged in data structures:

Functions

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?

Google is your friend

"?" is your friend

Try:

?lm()

Using help files

{height=500px}

Packages

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

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")

Google is your friend

Google

Good sources: r-bloggers.com, stackoverflow.com, ...

How the exercises work

How to access and update the package

# 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)

Assignment

Deadline: Next week Wednesday at 12:00

No submission is Zero for the assignment.

You will be graded on:

Links for this session

Intro to R
Troubleshooting
Etiquette
Data visualisation
Data visualisation 2
R Style guide



wardfont/edcpR documentation built on Dec. 23, 2021, 5:07 p.m.