R for Beginners
Chinese Edition 2.0
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
Co-translated by: XF Wang, YH Xie, JT Li and GH Ding
“R for beginners”R
20022005
Emmanuel ParadisLATEX
Chap1–2: Chap3: Chap4:
Chap5–7:
Rpwxf@hotmail.com
20064
c∞ 2002, 2005, Emmanuel Paradis
Permission is granted to make and distribute copies, either in part or in
full and in any language, of this document on any support provided the above
copyright notice is included in all copies. Permission is granted to translate
this document, either in part or in full, in any language provided the above
copyright notice is included.
1
2
2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 . . . . . . . . . . . . . . . . . . . . .
2.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 R
3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.1 . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.2 . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5.1 . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5.2 . . . . . . . . . . . . . . . . . . . . . .
3.5.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5.4 . . . . . . . . . . . . .
3.5.5 . . . . . . . . . . . . . . . . . . . . . .
3.5.6 . . . . . . . . . . . . . . . . . . . . . . . . .
3.5.7 . . . . . . . . . . . . . . . .
3.5.8 . . . . . . . . . . . . . . . . . . . . . . . . . .
4 R
4.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.1.1 . . . . . . . . . . . . . . . . . . . . .
4.1.2 . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.6
grid lattice . . . . . . . . . . . . . . . . . . . . . . . . . .
1
3
3
5
7
9
9
11
14
15
15
18
19
19
24
26
27
30
32
32
34
37
37
37
38
41
42
44
45
49
5 R
5.1 . . . . . . . . . . . . . . . . . . .
5.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 R
6.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3 . . . . . . . . . . . . . . . . . . . . . . . . .
7 R
56
56
58
59
62
65
65
67
68
72
1
R.
RR
RRoss Ihaka
Robert Gentleman1RAT&T
S1R
SInsightful2S-PLUSRS
Ihaka &
Gentleman (1996) R-FAQ3R
RGNUGeneral Public Licence4
RR Development Core Team
RUnix Linux
(CFortran )Windows, LinuxMacintosh
Comprehensive R Archive
Network (CRAN)5 Linux
LinuxCRAN
R
(jpg, png, bmp, ps,
pdf, emf, pictex, xfig; )
(P-)
R
R
S6,R
RR
R
“object”
1Ihaka R. & Gentleman R. 1996. R: a language for data analysis and graphics. Journal
of Computational and Graphical Statistics 5: 299–314.
2 http://www.insightful.com/products/splus/default.asp
3http://cran.r-project.org/doc/FAQ/R-FAQ.html
4For more information: http://www.gnu.org/
5http://cran.r-project.org/
6For example: http://stat.cmu.edu/S/
1
20
R
20
R
2
2
R
R‘>’Windows
Rgui.exe(
. . . )
R
R
(“assign”) (object)
.R
2.1
R
R
(CFortan, Pascal, . . . )
Rlm(y ~ x)
“xy”R
(,ls())
R
(object)
R(objects)
()()
(p. 26). R
arguments °!
options °!
function
"
default arguments
=)result
(argument)(. . . )
R
3
R
R
(p. 68)
R,
(Fig. 1)
()
keyboard
mouse
commands
-
functions and operators
æ
æ
-
.../library/base/
/stast/
/graphics/
...
library of
functions
data
files
internet
?
“data” objects
6
?
æ
XXXXXXXz
≥≥≥≥)
screen
“results” objects
PS JPEG . . .
Active memory
Hard disk
1: R.
R (library) ,
R HOME/library (R HOME R)
(packages )
baseRR
R
(base
R HOME/library/base/R/base)
R
n10
> n
[1] 10
1n
4