Software Tools for Earth and Environmental Science

–5th WEEK–

Emir Toker

18/10/2019

R Language - Part 1

  • Syllabus, Last Week, Book and This Week

  • R - Script, Notebook and Markdown

  • GitHub

  • R Language
    • Class
    • Vectors
    • Matrice
    • Arrays
  • PRACTICE and QUIZ

  • Next Week

Syllabus, Last Week, Book and This Week

Syllabus

Extended Syllabus PDF

Last Week

Week 4 - Presentation LINK

  • assigment <-
  • comments #

Book

(Pg. 22-27)

R Files

R Files

LINK

Scroll down :)

GitHub

GitHub

LINK

GitHub

GitHub

GitHub

R Language

R Language

  • Scientific Calculator

  • Class

  • Vectors

  • Matrices

  • Arrays

LINK

Practice, Summary and QUIZ

Practice

Scientific Calculator

Practice

Scientific Calculator

Problem: Compute double, triple or higher order integrals

install.packages("cubature")
library(cubature)

f <- function(x) 1
adaptIntegrate(f,lowerLimit = c(0,0,0),upperLimit = c(4,4,4))
$integral
[1] XX

Practice

Create a Function

Problem: Take a sample belonged to population and sum

pop <- 1:6                    # This is my population
samp <- sample(pop, size = 2) # This is my sample, I choose two var.
sum(samp)
pop
samp

I want to create a new function named roll()

roll <- function() {
pop <- 1:6 
samp <- sample(die, size = 2) 
sum(samp)
}
roll()

Practice

Create a Function

Problem: What if we removed one line of code from our function and changed the name pop to box ?

roll2 <- function() {
samp <- sample(box, size = 2) 
sum(samp)
}
roll2()

Re-create function

roll2 <- function(box) {
samp <- sample(box, size = 2) 
sum(samp)
}
roll2(box = 1:4)
roll2(box = 1:6)
roll2(1:20)

Practice

Create a Function

  • You can add new options
  • { } and () are important

Practice

  1. Print your name as a character string.
  2. Print your age as a numeric type.
  3. Print your age as a character type.

print()

  1. Create a numeric vector with your favorite numbers.
  2. Check the lenght of the vector, lenght().
  3. Choose the last element (indexing) with [].
  4. Create 4 × 2 matrice, fill with numbers
  5. Delete first row.
  6. Generate 48 random number and assign, runif().
  7. Create and store a three-dimensional array with six layers of a 4 × 2 matrice, and fill it with these random numbers.

Summary

  • Arithmetic Operators ( +, -, /, x )
  • Logical Operators ( <, >, ==, != ….)
  • Special Values ( NULL, Nan, NA, Inf)
  • Vector, Matrice, Array (1d and Homogeneous)
  • class(), print(), seq(), runif()
  • c(), []
  • ?xxx or help(xxx)
  • install.packages(), library()

QUIZ

https://kahoot.it/

Next Week

6th Week - R Language Part 2

List - Data Frame - Attributes - ATMOS

Homework

Udemy – Introduction to R, Section 3 (Video 22-25)

LINK

Quiz

List and Data Frame