roger barlow hep computing seminar 21 st february 2008
DESCRIPTION
R. Roger Barlow HEP Computing seminar 21 st February 2008. What is R?. A data handling+graphics system with particular emphasis on statistical tools Compare and contrast: PAW, Root, Easyplot, Matlab…. Getting hold of R. Google ‘R download’ and follow instructions Quite painless - PowerPoint PPT PresentationTRANSCRIPT
RRoger Barlow
HEP Computing seminar
21st February 2008
Roger Barlow: R Slide 2
What is R?
A data handling+graphics system with particular emphasis on statistical tools
Compare and contrast: PAW, Root, Easyplot, Matlab…
Roger Barlow: R Slide 3
Getting hold of R
Google ‘R download’ and follow instructions
Quite painless
Windows and unix versions exist
Roger Barlow: R Slide 4
Philosophy
1.1 The R environmentR is an integrated suite of software facilities for data manipulation, calculation
and graphical display. Among other things it has• an effective data handling and storage facility,• a suite of operators for calculations on arrays, in particular matrices,• a large, coherent, integrated collection of intermediate tools for data analysis,• graphical facilities for data analysis and display either directly at the computer
or on hardcopy,and• a well developed, simple and effective programming language (called ‘S’)
which includes conditionals, loops, user defined recursive functions and input and output facilities. (Indeed most of the system supplied functions are themselves written in the S language.)
The term “environment” is intended to characterize it as a fully planned and coherent system, rather than an incremental accretion of very specific and inflexible tools, as is frequently the case with other data analysis software.
Roger Barlow: R Slide 5
What do you get?
Command line for entering instructions
Help buttonGives help
And manuals
Screen whereplots appear
Roger Barlow: R Slide 6
Example: simple stuff
Roger Barlow: R Slide 7
Assignment and vectors
c means ‘concatenate’
Assignment operators
Roger Barlow: R Slide 8
Plotting
Roger Barlow: R Slide 9
Arguments
Type help
(“<whatever>”)
Eg
help(“rnorm”)
Roger Barlow: R Slide 10
More plotting
Roger Barlow: R Slide 11
Other plots
Roger Barlow: R Slide 12
Functions and scripts
Roger Barlow: R Slide 13
What was in the source file
print("Loading Fourier routines")PIBY2<-asin(1); PI<-2*piby2; TWOPI=2*PI; ROOT2PI=sqrt(TWOPI)alternation<-function(n) {2*(seq(1:n) %% 2)- 1}fourier<-function(data,lo,hi) { nbins <- length(data) nn=round(nbins/2) W <- hi-lo delta <- W /nbins ii<-seq(1,nbins)-1 x<-delta*ii+lo theta<-x*twopi/W fc<-seq(1,nn) fs<-seq(1,nn) for(i in seq(1,nn)){ fc[i]<- sum(cos(i*theta)*data) fs[i]<- sum(sin(i*theta)*data) } fc[nn]=fc[nn]/2 fs[nn]=0 list(c=2*fc/nbins,s=2*fs/nbins, zero=sum(data)/nbins)}
Roger Barlow: R Slide 14
Files and stuff
For hardcopy:>postscript(“<filename>”)>… plotting>dev.off()Also png(“<filename>”) and others
File input>s=read.table(“<filename>")>print(s$V1)>plot(s$V1,s$V2) etcOr read.table(“<filename>”,HEADER=TRUE)And first line of file will be taken as names used instead of V1, V2…
Roger Barlow: R Slide 15
Interested?
• Type demo() at the prompt