1 / 14

First Year R Computing Workshop

Join us for a hands-on workshop to learn how to use R for scientific calculations, data analysis, graph plotting, and more. Explore the power and versatility of R, an open-source statistical computing environment.

albertine
Download Presentation

First Year R Computing Workshop

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. First Year R Computing Workshop • Part of module PA1900 – 1st year laboratory • Venue: Computer terminal rooms G+H • Duration: 2x3 hour workshop sessions • Script on web: http://www.star.le.ac.uk/zrw/compshop

  2. Purpose of the Workshop • Learning how to use R to do the following • Simple scientific calculations • Plotting graphs • Defining and using functions • Using R scripts as computer programs • Creating, reading and writing ASCII data files • Linear fitting to data sets • Plotting measured data points including error bars • Performing simple numerical differentiation and integration • Plotting and analysing functions of 2 variables or 2-d images • Using R for analysis and plotting in labs

  3. What is R? • R is an open-source environment for • statistical computing • visualisation (plotting graphs, pictures…) • R is an excellent general programming environment beyond statistics • R is free and freely available • http://www.r-project.org/ • Download R onto your own laptop

  4. Getting started with R • Logon to a UoL IT Windows machine. • StartAllProgramsR for WindowsR 3.0.0 (64-bit) click • Use Windows Explorer to create a new folder (directory) where you will save all your R files. • My Documents/Rwork • Use the Rwork folder as the working directory for R. In the R GUI use the File menu top left • FileChange dir click • Type commands at prompt > in the R console.

  5. The R Working Directory and Quitting > setwd(“Rwork”) set the working directory > getwd() [1] “Z:/My Documents/Rwork” get the working directory (and list) > list.files() list the files in the working directory > q() quit R – don’t save workspace

  6. Getting Help Help menu at the top of GUI screen HelpHtml help click for general browsing HelpR functions (text) click for help on known function/command

  7. The R Console Navigate through previous lines using simple control key stokes ctrl-p go to previous line ctrl-n go to next line ctrl-a go to start of current line ctrl-e go to end of current line ctrl-b go back 1 character ctrl-f go forward 1 character Cut and past ctrl-c cut text highlighted using cursor to clipboard ctrl-v paste text from clipboard to current position Complete word facility – TAB (left-hand little finger) HelpConsole

  8. Variables, Objects and Assignment > x <- 3*pi > x [1] 9.424778 > x <- 1:5 > x [1] 1 2 3 4 5 > y <- sin(x) > y [1] 0.8414710 0.9092974 0.1411200 -0.7568025 -0.9589243

  9. Plotting Graphs > x <- 1:100 > x <- sin(x)*exp(-x/100) > plot(x,y,type=“l”)

  10. R Script Files • Edit a script file and save (mysource.R) • File New script click • File Open script click • File Saveclick File saved in the current working directory • Source the script file (run the script) • File Source script click > source(“mysource.R”)

  11. Data Files • You can create and edit data files in the same way as R script files. • Use the file name extension .dat (not .R). • The data files will be stored in the working directory. • Arrange the data in columns with a header at the top. V T P 1.000 293.3 1.202 1.053 281.8 1.117… • Read the file into a R data frame using > mydat <- read.table(“myfile.dat”,header=TRUE)

  12. The Power of R • There are many, many statistical and analysis applications available in R. • Use R for analysis and plotting in labs. • You will use R when learning probability and statistics in the 1st year. • R is used in the Fractals and Chaos course in the 2nd year. • R is used to teach Scientific Inference. • Use R for project work in 3rd/4th years.

  13. Things to do now Before you come to your timetabled workshop • Log in to your UoL account • Get the script from http://www.star.le.ac.uk/zrw/compshop • Start R from All Programs • Create a working directory My Documents/Rwork We recommend that you • Download R onto your own laptop http://www.r-project.org/

  14. And finally… • The workshop and laboratory timetable is on Blackboard and on the Laboratory Notice Board – find out YOUR timetable • Go to Room F in the Department of Physics and Astronomy to collect your Laboratory Course Books – NOW Good luck!

More Related