ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the...

15
Installing R-Studio on Windows 7 / Mac OS 10.6 (+) ATM 315 Environmental Statistics Course 2014-01-23 1 Goto http://www.rstudio.com / Follow the link and then choose the desktop application Download the R base package (see also next page) & R-Studio Follow the instructions of the Installer First download & install the R base package Then download & install RStudio Follow the link

Transcript of ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the...

Page 1: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

1

Installing R-Studio on Windows 7 / Mac OS 10.6 (+)

ATM 315 Environmental Statistics Course 2014-01-23

• Goto http://www.rstudio.com/• Follow the link and then choose the desktop application• Download the R base package (see also next page) & R-Studio• Follow the instructions of the Installer

First download & installthe R base package

Then download & install RStudio

Follow the link

Page 2: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

2

Installing R from the CRAN project pages

ATM 315 Environmental Statistics Course 2014-01-23

www.cran.us.r-project.org

Page 3: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

3

A first session with R-Studio (Windows 7)

ATM 315 Environmental Statistics Course 2014-01-23

Command-line window

Multi-function Window

(for file browsing, plotting, Software package management …

Memory window: list of objectsCurrently in the memory for use

Page 4: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

4

A first session with R-Studio (Windows 7)

ATM 315 Environmental Statistics Course 2014-01-23

Menu list for the R-Studio:

(1) Set your work path for the Session (and current sessions)

Command-line window

Your files in the directory

I suggest for this course:Create your atm315course directorywith 3 sub-directories:(1) scripts(2) data(3) figures

R-scripts (programs) are plain text files with ending .R ( NOT formatted Word documents)

Page 5: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

5

Our first R-session

We first set the working directory for the session (in menu ‘session’, choose ‘set working directory’)

Or type into the command line window ( in windows it will start with C:/Users), MAC it will start with /Users/)

setwd("C:/Users/oe524132/WORK/111TEACHING/R-course")

Subdirectory ‘data’

Collection of datasets(input data and output data)

Subdirectory ‘scripts’

Contains the scripts.Scripts are text files ending ‘.R’They contain program codes that can be executed

Subdirectory ‘figures’

We will collect our plots in this directory

Your working directory should have three subdirectories:

Page 6: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

6

Our first R-session

With Windows File Browser tool / Mac Finder go into any directory of your choice Create a new folder (named e.g. “R-Course”). Then enter the folder and Create 3 new folders in there: “scripts” , “data”, “figures”

NEXT start R-Studio and set the working directory for the session (in menu ‘session’, choose ‘set working directory’) Or type into the command line window

(in windows it will start with C:/Users), MAC it will start with /Users/)

In my case the directory path in set setwd("C:/Users/oe524132/WORK/111TEACHING/R-course")

(your path name will differ of course on your system)

source(“scripts/hadcrut4.R”)

NOTE: R commands and scripts are case sensitve (i.e. the function call “Source(“scripts/hadcrut4.R)” doesn’t work!

Page 7: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

7

Our first R-session

We first set the working directory for the session (in menu ‘session’, choose ‘set working directory’)

Or type into the command line window ( in windows it will start with C:/Users), MAC it will start with /Users/)

setwd("C:/Users/oe524132/WORK/111TEACHING/R-course")

source(“scripts/hadcrut4.R”)

NOTE: R commands and scripts are case sensitve (i.e. the function call “Source(“scripts/hadcrut4.R)” doesn’t work!

Page 8: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

8

example001.R

Our first R-session: data types and objects

Page 9: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

9

example001.R

Our first R-session: data types and objects

example001.R

Page 10: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

10

example001.R

Our first R-session: data types and objects

Page 11: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

11

example001.R

Our first R-session: data types and objects

Page 12: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

12

HADCRUT4 global annual mean temperature anomalies

Global warming trend

Our first R-session

A good habit: give reference /credit to the data source and date of retrieval. Acknowledge the developers of thedata sources: Morice, C. P., J. J. Kennedy, N. A. Rayner, and P. D. Jones (2012),

J. Geophys. Res., 117, D08101, doi:10.1029/2011JD017187.

Data retrieved from http://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/download.html2014-01-20, [Version HadCRUT.4.2.0.0 (file HadCRUT.4.2.0.0.annual_ns_avg.txt)]

Global warming stalled?

Page 13: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

13

Our first R-session script: hadcrut4.R

Page 14: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

14

example001.R

hadcrut4.R

Our first R-session: Global mean temp.

Page 15: ATM 315 Environmental Statistics Course 2014-01-23 1 Goto // Follow the link and then choose the desktop application.

15

NOTES