POLI 324 Lecture Notes - Lecture 11: Jorge Ahumada, Computer Language, Computational Statistics
Rfor Beginners
Emmanuel Paradis
Institut des Sciences de l’ ´
Evolution
Universit´e Montpellier II
F-34095 Montpellier c´edex 05
France
E-mail: paradis@isem.univ-montp2.fr
Ithank Julien Claude, Christophe Declercq, ´
Elodie Gazave, FriedrichLeisch,
Louis Luangkesron, Fran¸cois Pinard, and Mathieu Ros for their comments and
suggestions on earlier versions of this document. Iam also grateful to all the
members of the RDevelopmentCore Team for their considerable efforts in
developing Rand animating the discussion list ‘rhelp’. Thanks also to the
Rusers whose questions or comments helped me to write “R for Beginners”.
Special thanks to Jorge Ahumada for the Spanish translation.
c
⃝2002, 2005, Emmanuel Paradis (12th September 2005)
Permission is granted to makeand distribute copies, either in part or in
full and in anylanguage, of this documenton anysupport provided the above
copyrightnotice is included in all copies. Permission is granted to translate
this document, either in part or in full, in anylanguage provided the above
copyrightnotice is included.
Contents
1 Preamble 1
2 A few concepts before starting 3
2.1 How R works ............................ 3
2.2 Creating, listing and deleting the objects in memory ...... 5
2.3 The on-line help .......................... 7
3Data with R9
3.1 Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Reading data in afile ....................... 11
3.3 Saving data ............................. 14
3.4 Generating data .......................... 15
3.4.1 Regular sequences . . . . . . . . . . . . . . . . . . . . . 15
3.4.2 Random sequences . . . . . . . . . . . . . . . . . . . . . 17
3.5 Manipulating objects . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5.1 Creating objects ...................... 18
3.5.2 Converting objects . . . . . . . . . . . . . . . . . . . . . 23
3.5.3 Operators .......................... 25
3.5.4 Accessing the values of an object: the indexing system .26
3.5.5 Accessing the values of an object with names ...... 29
3.5.6 The data editor ....................... 31
3.5.7 Arithmetics and simple functions ............. 31
3.5.8 Matrix computation .................... 33
4Graphics with R36
4.1 Managing graphics ......................... 36
4.1.1 Opening several graphical devices ............. 36
4.1.2 Partitioning agraphic ................... 37
4.2 Graphical functions ......................... 40
4.3 Low-level plotting commands ................... 41
4.4 Graphical parameters ....................... 43
4.5 Apractical example . . . . . . . . . . . . . . . . . . . . . . . . 44
4.6 The grid and lattice packages ................... 48
5Statistical analyses with R55
5.1 Asimple example of analysis of variance ............. 55
5.2 Formulae .............................. 56
5.3 Generic functions .......................... 58
5.4 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61