You are on page 1of 48

R

R frequently asked questions


http://www.r-project.org

153 R

This document is generated from LATEXsources compiled with xeLATEX


in a Windows platform. The used packages are amsmath, listings, makeidx and so on.

R R_introR_dataR_admin
contributed documents Capital Of Statistics

R R

R CRAN Task Views


R Packages
R
R
44 R

1 2
February 4, 2013

abel,cran,rtist,Xie Yihui,zhangv

1
http://www.bjt.name/todo
2
sunbjt<at>gmail.com
A

1. R
R
Ross Ihaka Robert Gentleman R Becker, Chambers & Wilks S
Sussman Scheme R S

2. R
R http://cran.r-project.org/mirrors.html
UC BerkeleyR LinuxMacOS XWindows
Windows Windows (95 and later) base R-x.x.x-
win32.exe

3. R R
R (Robert Gentleman Ross Ihaka)
S S GNU S

4. CRAN
CRAN Comprehensive R Archive N etwork
R

5. R
R
R
http://cran.r-project.org/other-docs.html
BBS R

6. R R-intro
R-intro R R
R-intro

7. R
153 R R
R

R
R

2

Modern Applied Statistics with SVenables and Ripley
The New S Language: A Programming Environment for Data Analysis and Graphics
Richard A. BeckerJohn M. ChambersAllan R.Wilks
A Handbook of Statistical Analysis Using RBrian S. EverittTorsten Hothorn
Data Analysis and Graphics using RMaindonald and Braun
Introductory Statistics with RDalgaard
R in a nutshell

8. R
R
R

9. R
100 100
1 x < rnorm ( 1 0 0 , mean = 5 , sd = 0 . 1 )
mean ( x )
3 sd ( x )
summary ( x )
demo() R
demo ( g r a p h i c s )

10. R
R GNU General Public License (GPL)

11. R 50% CPU


Windows CPU CPU
R 2 CPU
CPU 50%

12. R
LATEX R citation() BibTEX

1 c i t a t i o n ( package = package )

3
B

13.
R ? topic help(topic) topic
help.search(topic)
apropos(tab)
tab
R Site Search http://finzi.psych.upenn.edu/
search.html R RSiteSearch()

14. R
R R
R

R R CMD Rterm

1 r maxmems i z e =1Gb

RHOME/bin 3

1 r g u i maxmems i z e =1Gb

R memory.limit R
32 R 32Mb 3Gb 64
32 Windows 2Gb 32
Windows R 32Mb 2Gb

15. help.search()
Java Java Javascript

16. R
R

par family
2.14.0 R cairo

1 png ( f o o . png , type = c a i r o , , f a m i l y=SimSun )


p l o t ( 1 , type = n )
3 t e x t ( 1 , 1 , cairo )
3
Rterm

4
dev . o f f ( )

SimHeiKaiTi_GB2312YouYuanLiSu
cairo family = GB1

17. R Tab completion


2.5.0 R Tab R
Tab

18.
rm()

rm( l i s t = l s ( a l l = TRUE) )

19.
options(digits = ) digits 1 22 7options
(prompt) (show.error.messages)

20.
system() shell.exec() :

1 # go t o t h e c r a n
system ( p a s t e ( C : / Program F i l e s / I n t e r n e t E x p l o r e r / i e x p l o r e . exe ,
3 c r a n . rp r o j e c t . o r g ) , w a i t = FALSE)
# i n v o k e t h e notepad
5 system ( notepad )
s h e l l . e x e c ( C : /WINDOWS/ c l o c k )

21. Windows R packages


R 3
Windows Contributed Packages

R R
library library R R

update . p a c k a g e s ( c h e c k B u i l t = TRUE, ask = FALSE)


2 # o r i n s t a l l . p a c k a g e s ( . p a c k a g e s ( a l l = TRUE) )

22. packages

remove . p a c k a g e s ( c ( pkg1 , pkg2 ) ,


2 l i b = f i l e . path ( path , t o , l i b r a r y ) )

23. R
Windows XP R

C: \ Documents and S e t t i n g s \ username

getwd() R (Working Directory) setwd()


24.
save.image() R working space.RData
save(..., le = ) R

25. R
R
4

26. library()
R

1 d e t a c h ( package : pkg )

27. Library Package


R Package LibraryLibrary
Package Package
LibraryWindows *.zip

28. Package
search()

1 . p a c k a g e s ( a l l . a v a i l a b l e = TRUE)


R R Package
4
R UnixMacWindows

6
R

stats
graphics
grDevices grid
utils R
datasets
methods R
base

29. R
R datasets 102 data()

1 dim ( data ( ) $ r e s u l t s )
data ( ) $ r e s u l t s [ , 4 ]

30. R
RS class



1 charactor
2 numeric
3 integer
4 logical TRUE=TFALSE=F
5 complex a
6 list S
7 factor
a
18
RS

Everything in S is an object;
Every object is S has a class.

31. data frame


data frame
matrix-like

7
32.
R

dist

Generic Function
methods() 5

1 summary # I t i s a g e n e r i c f u n c i t o n
methods ( summary ) # l i s t o f t h e S3 methods
3 summary . lm # maybe you want t o know t h e l i n e a r models s summary

*.tar.gz R-2.5.1.tar.gz

33.
head() tail()

1 head (CO2)


car some

34. R
lmglm y model y
model model + :
+ : a + b + a : b (a + b + c) 2 (a + b + c) (a + b + c)
abc (a + b + c) 2 a : b
a + b + c + b : c + a : c

log(y) a + log(x)

. update

1 fm < aov ( Speed ~ Run + Expt )


fm0 < update ( fm , . ~ . Run)

H lattice |

35. R

5
getAnywhere()

8
1 e10 == 10000000000
2 1 . 2 e4 == 0 . 0 0 0 1 2

36. R
foreign Minitab, S, SAS, SPSS, Stata, Systat, dBase
Hmisc sas.get, spss.get SAS SPSS
foreign
.csv

37. R Excel
Excel Excel
Excel
1. Excel csv(Comma Separated Values) read.csv()
2. RODBC odbcConnectExcel() xls

l i b r a r y (RODBC)
2 z < odbcConnectExcel ( r e x c e l t e s t . x l s )
dd < s q l F e t c h ( z , S h e e t 1 )
4 close (z)

R Data Import/Export
3. xlsReadWrite read.xls

38. R
sink()

data (CO2)
2 s i n k ( CO2 . t x t )
CO2
4 sink () # go t o your work d i r e c t o r y , you w i l l g e t CO2 . t x t

39. R
R capture.output() R

glmout < c a p t u r e . output ( example ( glm ) )


2 glmout [ 1 : 5 ]

9
Go to LATEX!

40. R

data < r e a d . t a b l e ( c l i p b o a r d )
2 write . table ( clipboard )

41. (factor)
f

a s . numeric ( a s . c h a r a c t e r ( f ) )
2 # or
a s . numeric ( l e v e l s ( f ) ) [ a s . i n t e g e r ( f ) ]

factor factor
character

42. R
edit() x()

1 data < data . frame ( )


edit (x) ; fix (x)

naive

43. source()
print() source(le, echo = TRUE) R
sink() source(le, echo = TRUE)
sink

44. R TEX
Hmisc latex() xtable xtable()

a < matrix ( 1 : 6 , nr =1) # require ( xtable )


2 colnames ( a ) < p a s t e ( c o l , 1 : 6 )
xtable (a)

xtable() HTML R
wordpowerpoint
LATEX quantreg latex.table()

10
45.
R

1 d : \ \R 2 . 4 . 1 \ \ l i b r a r y \\ x g o b i \\ s c r i p t s \\ x g o b i . bat
d : /R 2 . 4 . 1 / l i b r a r y / x g o b i / s c r i p t s / x g o b i . bat

le.choose() Windows
choose.dir() Windows ,

46. R
SQL R SQL
OracleMicrosoft SQL ServerIBM DB2
GNU General Public License (GPL) MySQL
RMySQL 6 MySQL RODBC
ODBC R

l i b r a r y (RODBC)
2 ch < odbcConnect ( stocksDSN , u i d = myuser ,pwd = mypassword )
s t o c k s < s ql Q u e r y ( ch , s e l e c t * from q u o t e s )
4 o d bc C l o s e ( ch )

Windows Microsoft SQL ServerAccessOracleMySQLPostgreSQL


Linux MySQLOraclePostgreSQLSQLite R-
data

47.
R NAnot available RS NA
7

x < NA
2 x > 3
class (x)

1 x == NA
6
DBI
7
R TRUEFALSENA

11
is.na()
1 x [ ! i s . na ( x ) ]

48.
eval() parse() parse() expression
eval()
1 x < 1 : 1 0
a < p r i n t ( x )
3 class (a)
eval ( parse ( text = a ))
expression
a < 3
2 x < 4
s t r 2 e x p r < f u n c t i o n ( x ) { e v a l ( p a r s e ( t e x t = x ) ) }
4 s t r 2 e x p r ( a + a* s q r t ( x ) )
x x eval expression
eval x x x sqrt

a < 3
2 x < 4
s t r 2 e x p r < f u n c t i o n ( y ) { e v a l ( p a r s e ( t e x t = y ) ) }
4 s t r 2 e x p r ( a + a* s q r t ( x ) )
eval .GlobalEnv
s t r 2 e x p r < f u n c t i o n ( x ) { e v a l ( p a r s e ( t e x t = x ) , . GlobalEnv ) }

49.
append()
1 x < 1 : 5
( f o o < c ( x [ 1 ] , 0 , x [ 2 : 5 ] ) ) # expected r e s u l t
3 append ( x , 0 , a f t e r = 1 )

50. ()
subset(select = )

12
1 x < data . frame ( matrix ( 1 : 3 0 , nrow = 5 , byrow = T) )
dim ( x )
3 print (x)
new . x1 < x[ c ( 1 , 4 ) , ] #row
5 new . x2 < x [ , c [ 2 , 3 ] ] #c o l
new . x1 ; new . x2

subset

i S < i r i s $ S p e c i e s == s e t o s a
2 i r i s [ iS , c ( 1 , 3 ) ]
s u b s e t ( i r i s , s e l e c t = c ( S e p a l . Length , P e t a l . Length ) ,
4 S p e c i e s == s e t o s a )

51.

a1 < data . frame (num = 1 : 8 , l i b = l e t t e r s [ 1 : 8 ] )


2 a2 < a1
a2 [ [ 3 , 1 ] ] < 2 > a2 [ [ 8 , 2 ] ]
4 any ( a1 !=a2 ) # a l l ( a1 == a2 )

any()

a1 !=a2

TRUE any() TRUE identical()

1 i n d e n t i c a l ( a1 , a2 )

1 which ( a1 !=a2 , a r r . i n d = TRUE)

arr.ind array indices

52.
unique unique

1 x < c ( 9 : 2 0 , 1 : 5 , 3 : 7 , 0 : 8 )
( xu < x [ ! d u p l i c a t e d ( x ) ] )
3 unique ( x ) # i s more e f f i c i e n t

duplicated

13
53. array
aperm

1 x < a r r a y ( 1 : 2 4 , 2 : 4 )
xt < aperm ( x , c ( 2 , 1 , 3 ) )
3 dim ( x ) ; dim ( xt )

54. list
R NULL

1 l s t < l i s t ( a = l i s t ( b =1, c =2) , b= l i s t ( d =3, e =4))


l s t [ [ a ] ] [ b ] < NULL # o r l s t $ a$b < NULL
3 lst

55. ()
apply()

1 vec =1:20
mat=matrix ( vec , n c o l =4)
3 vec
cumsum ( vec )
5 mat
apply ( mat , 2 , cumsum )
7 apply ( mat , 1 , cumsum )

56. R
(Regular Expres-
sion) *.R source(*.R) #

1 i f (FALSE) {
something passby
3 }

57. (data frame)


transform() ?transform

58.
pmax() pmin()

14
1 x < 1 : 1 0 ; y < r e v ( x )
pmax ( x , y ) ; pmin ( x , y )

59.
tapply()

n < 1 7 ; f a c < f a c t o r ( r e p ( 1 : 3 , l e n = n ) , l e v e l s = 1 : 5 )
2 table ( fac )
t a p p l y ( 1 : n , f a c , sum )
4 t a p p l y ( 1 : n , f a c , mean )
## o r r e v e r s e a l i s t
6 t o < l i s t ( a = 1 , b = 1 , c = 2 , d = 1 )
t a p p l y ( t o , u n l i s t ( t o ) , names )

tapply() meanvarsd
aggregate() tapply() 8

1 a t t a c h ( warpbreaks )
t a p p l y ( breaks , l i s t ( wool , t e n s i o n ) , mean )
3 a g g r e g a t e ( breaks , l i s t ( wool , t e n s i o n ) , mean )
## from t h e h e l p
5 a g g r e g a t e ( s t a t e . x77 ,
l i s t ( Region = s t a t e . r e g i o n ,
7 Cold = s t a t e . x77 [ , F r o s t ] > 1 3 0 ) ,
mean )

60.
sapply

s a p p l y ( dataframe , i s . numeric )

sapply dataframe

1 s a p p l y ( l s ( ) , f u n c t i o n ( x ) round ( o b j e c t . s i z e ( g e t ( x ) ) / 1024 / 1 0 2 4 ) )

61.
sample()
8

15
sample(n) 1, . . . , n
sample(x) x, length(x) > 1
sample(x, replace = T)
sample(x,n) x n
sample(x,n, replace = T) x n
sample(x,n, replace = T ,prob = p) p x n

1 n < 1000
x < sample ( c ( 1 ,1) , n , r e p l a c e=T)
3 p l o t ( cumsum ( x ) , type= l ,
main= Cumulated sums o f B e r n o u l l i v a r i a b l e s )

20

rnorm ( 1 0 0 , mean=0, sd =1)

62.

merge(x, y ,by.x = ,by.y = ,all = )
SQL sqldf
R SQL

1 example ( merge )
s q l d f ( s e l e c t * from a u t h o r s a1 , books a2
3 where a1 . surname = a2 . name , method = c h a r a c t e r )
(m1 < merge ( a u t h o r s , books , by . x = surname , by . y = name ) )

sqldf SQL

63.
scale

x < c ( rnorm ( 1 0 0 ) , 2 * rnorm ( 3 0 ) )


2 m < s c a l e ( x , s c a l e = F) # only c en t e ri n g
n < s c a l e ( x , c e n t e r = F) # o n l y s c a l i n g

64. venum summary


1 > fivenum ( c ( 1 , 4 , 6 , 1 7 , 5 0 , 5 1 , 7 0 , 1 0 0 ) )
[1] 1.0 5.0 33.5 60.5 100.0

16
3 > quantile ( c (1 ,4 ,6 ,17 ,50 ,51 ,70 ,100))
0% 25% 50% 75% 100%
5 1.00 5.50 33.50 55.75 100.00

9 14 , 34

1 1
1 + (length(x) 1),
4 4
3 3
1 + (length(x) 1),
4 4

1 c (1 ,4 ,6 ,17 ,50 ,51 ,70 ,100)


7 21
1+ = 2.75, 1 + = 6.25
4 4

4 + (6 4) 0.75 = 5.5, 51 + (70 51) 0.25 = 55.75

venum() NL NU
length(x) lenght(x)
NL , NU

65.
R integrate

1 i n t e g r a t e ( dnorm , 1.96 , 1 . 9 6 )
i n t e g r a t e ( dnorm , I n f , I n f )
3 ## a s l o w l y c o n v e r g e n t i n t e g r a l
i n t e g r a n d < f u n c t i o n ( x ) {1 / ( ( x+1)* s q r t ( x ) ) }
5 i n t e g r a t e ( i n t e g r a n d , l o w e r = 0 , upper = I n f )

66.
t() R x integer t(t(x))

9
summary()

17
1 x < 1 : 1 0 ; class (x)
t (x) ; class ( t (x))
3 t ( t (x)) ; class ( t ( t (x )))

1 x%*%x
xT x xxT %o% outer() crossprod()
1 XT. y < c r o s s p r o d (X, y )
X T Y crossprod() 10

outer()

sin x2 + y 2
10
x2 + y 2

R
1 f < f u n c t i o n ( x , y ) { r < s q r t ( x^2+y ^ 2 ) ; 10 * s i n ( r ) / r }
z < o u t e r ( x , y , f )

67. R
complex()
x < 1 + 1 i # x < complex ( 1 , 1 )
2 Mod( x ) ; Conj ( x )

68.
diag() Z
Z

69.

1 2 2
1
eigen A = 2 1 2 B = ( A1 ) + E
2
2 2 1

A < matrix ( c ( 1 ,2 ,2 ,2 , 1 , 2 ,2 , 2 , 1) ,3 ,3)


2 m < s o l v e ( 0 . 5 *A) + d i a g ( c ( 1 , 1 , 1 ) )
e i g e n (m)
solve()
10
,

18
1 a%*%x = b

70.
lower.tri() upper.tri()

1 Rmat < matrix ( 1 : 1 6 , 4 , 4 )


Rmat [ l o w e r . t r i (Rmat ) ] < 0
3 Rmat

71.
x(1/3) R sqrt()
R

1 ^ ( x , 1 / 3 )

R
R
+,-,*,/,,%%,%/%
>, <, >=, <=, ==, ! =

72. ()
apply() rowMeans() colMeans()

1 m < 1000 ; n < 3000


A < matrix ( 1 :m*n ,m , n )
3 system . time ( B1 < matrix ( apply (A, 2 , mean ) , m, n , by = TRUE) )
system . time ( B2 < matrix ( colMeans (A) , m, n , by = TRUE) )

sqldf

73.
( )
choose() nk combn() factorial()

!n
Cnm =
!m!(n m)

74. R
D()

19
f 1 < e x p r e s s i o n ( s i n ( x ) *x )
2 f 2 < e x p r e s s i o n ( x^2*y + y ^2)
D( f , x )

75.
rnorm(n , mean , sd) n mean sd
R d p q
r 24
R-intro Probability distributions

1 help . search ( d i s t r i b u t i o n )

X N (3, 1)
P (2 6 X 6 5)

pnorm

1 pnorm ( 5 , 3 , 1 ) pnorm ( 2 , 3 , 1 )

0.8185946 1
0.4
0.3
Density

0.2
0.1

P(2<x<5)
0.0

2 0 2 4 6 8

Figure 1:

76.
uniroot() uniroot

1 f <f u n c t i o n ( x ) x^3 2 *x 1
uniroot ( f , c (0 ,2))

optimize()

20
f < f u n c t i o n ( x ) x^2 + 2 *x + 1
2 o p t i m i z e ( f , c ( 2 ,2))

77. R
R Unix R tolower() toupper()
casefold()

x < MiXeD cAsE 123


2 c h a r t r ( iXs , why , x )
c h a r t r ( acX , DFw , x )
4 tolower (x)
toupper ( x )

78. R
paste()

1 f o r ( var i n l e t t e r s [ 1 : 6 ] ) {
x < var
3 w r i t e . t a b l e ( x , p a s t e ( FOO_ , var , . t x t , s e p = ) )
} # You w i l l g e t FOO_a . t x t . . .

79. R Regular Expressions


R extended regular expressions grep(extended
= TRUE) basic regular expressions grep(extended = FALSE)Perl-like regular
expressions grep(perl = TRUE) . \. .

g r e p ( J . , month . abb )

help(regex)

80.
substr()

1 substr ( abcdef ,2 ,4)


substring ( abcdef , 1 : 6 , 1 : 6 )

21
xml html XML
XML XML

81.
lengthlength
nchar

nchar ( )
2 [1] 3
l e n g t h ( )
4 [1] 1

82.
as.Date() as.POSIXct()
Date Date

d1 < c ( 06 / 29 / 07 ) ; d2 < c ( 07 / 02 / 07 )
2 D1 < a s . Date ( d1 , %m/%d/%y )
D2 < a s . Date ( d2 , %m/%d/%y )
4 D1 + 2 ; D1 D2
d i f f t i m e (D1 , D2 , u n i t s = days )

1 a s . Date ( 22JUN01 , format= %d%b%y )

Sys.setlocale(LC_TIME, C)

83. , 22 2007
format()

1 format ( Sys . Date ( ) , format=%A, %d %B %Y )

format help(strptime) details

84.

22

par(mfrow = c(2,2)) par(mfcol = c(2,2))
layout
split.screen()
layout() Statistics with R

1 l a y o u t ( matrix ( c ( 1 , 1 , 1,
2, 3, 4,
3 2, 3, 4 ) , nr = 3 , byrow = T) )
h i s t ( rnorm ( 2 5 ) , c o l = VioletRed )
5 h i s t ( rnorm ( 2 5 ) , c o l = VioletRed )
h i s t ( rnorm ( 2 5 ) , c o l = VioletRed )
7 h i s t ( rnorm ( 2 5 ) , c o l = VioletRed )

85.
par(mar = c(bottom, left, top, right))bottom, left, top, right
bottom, left, top, right c(5, 4, 4, 2) + 0.1
par(mai = c(bottom, left, top, right))

86. pch
pch plotting character pch 0 : 25 26
pch #, %, , |, +, , ., o, O21 : 25
points bg =

1 op < par ( bg = l i g h t b l u e )
x < s e q ( 0 , 2 * pi , l e n = 5 1 )
3 p l o t ( x , s i n ( x ) , type = o , bg = par ( bg ) )
p o i n t s ( x , s i n ( x ) , pch = 2 1 , cex =1.5 , bg= r e d )

87.

23
abline()y h=x v=
a= b=
R High_levelLow_level Interactive




88.
x dfunction(x)
x=s e q ( 3 , 3 , . 0 5 )
2 p l o t ( x , dnorm ( x ) , type= l ,
y l a b = , main = The normal and t d i s t r i b u t i o n )
4 l i n e s ( x , dt ( x , 1 ) , c o l = r e d )
l e g e n d ( t o p r i g h t , c ( normal , t ) ,
6 c o l = c ( black , red ) , l t y = 1)

dfunction(x) function R-intro Probability distributions


help.search(distribution) 20

R
R
beta beta shape1(),shape2()
binom size(n),prob(p)
2 chisq df
unif min(a),max(b) min = 0, max = 1
exp rate rate = 1
F f df1(r1 ),df2(r2 )
gamma shape(),scale() scale = 1
hyper m = N1 , n = N2 , k = n
norm mean(),sd() mean = 0, sd = 1
pois lamda()
t t df
weibull shape(),scale() scale = 1

89.

24
legendhelp(legend)

with ( i r i s , p l o t ( S e p a l . Length , S e p a l . Width ,


2 pch=a s . numeric ( S p e c i e s ) , cex = 1 . 2 ) )
legend (6.1 , 4.4 , c ( setosa , v e r s i c o l o r , v i r g i n i c a ) ,
4 cex =1.5 , pch =1:3)

90.
pie()
bar chartdot chart

91.
stem

stem ( f a i t h f u l $ e r u p t i o n s )

92. R
R par(new = TRUE) (hight-level plot)

GDP (UR)

1 y e a r < 1 9 9 5 : 2 0 0 5
x1 < data . frame ( year , GDP = s o r t ( rnorm ( 1 1 , 1 0 0 0 , 1 0 0 ) ) )
3 x2 < data . frame ( year , UR = rnorm ( 1 1 , 5 , 1 ) )
par ( mar = c ( 5 , 4 , 4 , 6 ) + 0 . 1 )
5 p l o t ( x1 , a x e s = FALSE, type = l )
a x i s ( 1 , a t = year , l a b e l = y e a r )
7 axis (2)
par ( new = TRUE, mar = c ( 1 0 , 4 , 1 0 , 6 ) + 0 . 1 )
9 p l o t ( x2 , a x e s = FALSE, x l a b = , y l a b = ,
c o l = r e d , type= b )
11 mtext ( UR(%) , 4 , 3 , c o l = r e d )
a x i s (4 , c o l = red , c o l . a x i s = red )

plotrix twoord.plot()

twoord . p l o t ( 2 : 1 0 , s e q ( 3 , 7 , by = 0 . 5 ) + rnorm ( 9 ) ,
2 1 : 1 5 , r e v ( 6 0 : 7 4 ) + rnorm ( 1 5 ) , x l a b= Sequence ,
y l a b= Ascending v a l u e s , r y l a b= Descending v a l u e s ,
4 main= Test o f twoord . p l o t )

25
R

93.
R ?Devices

R

x11 X
windows Windows
postscript ps
pdf pdf
pictex LATEX
png png
jpeg jpeg
bmp bmp
xg XFIG
win.metale a emf
a
Windows

pdf() pdf 2.14.0


R cairo cairo pngjpg

94.
grid()
plot (1:3)
2 g r i d (NA, 5 , lwd = 2 ) # g r i d o n l y i n yd i r e c t i o n

95.
strwrap
p l o t ( 0 , main = p a s t e ( s t r w r a p ( This i s a r e a l l y l o n g t i t l e t h a t
2 i can not type i t p r o p e r l y , width = 50 ) ,
c o l l a p s e = \n ) )

96.

26
dev.list()
dev.cur()dev.set()dev.o()

97. y

1 ? par # see las


p l o t ( 0 , 0 , xaxt=n , type=n , ylim=c ( 0 , 1 0 0 ) , l a s = 1 )
3 mtext ( 35 , s i d e = 2 , a t = 3 5 , l i n e = 1 , l a s = 1 )

98.
R stars

1 s t a r s ( s t a t e . x77 [ , c ( 7 , 4 , 6 , 2 , 5 , 3 ) ] , f u l l = FALSE,
key . l o c = c ( 1 0 , 2 ) )

full = FALSE key.loc


99. R 8
col R 8

palette ()
2 b a r p l o t ( rnorm ( 1 5 , 10 , 3 ) , c o l = 1 : 1 5 )
p a l e t t e ( rainbow ( 1 5 ) )
4 b a r p l o t ( rnorm ( 1 5 , 10 , 3 ) , c o l = 1 : 1 5 )
palette ( default )

R 657

1 colors ()

R 502
rgb()

100.
col barplot()
(color sets)

27
R

rainbow() ( )
heat.colors() ( )
terrain.colors() ( )
topo.colors() ( )
cm.colors() ( )
gay()grey() ( )

1 x < 1 : 1 0 ; names ( x ) < l e t t e r s [ 1 : 1 0 ]


barplot (x , c o l = rev ( heat . c o l o r s ( 1 0 ) ) )
3 b a r p l o t ( x , c o l = gray ( ( 1 : 1 0 ) / 1 0 ) ) ;
R RColorBrewer colorRamps RCol-
orBrewer sequentialdivergingqualitative

101. R RGB
col2rgb()
1 w r i t e . t a b l e ( t ( c o l 2 r g b ( rainbow ( 7 ) ) / 2 5 5 ) , s e p = , )

102.
Windows
savePlot()
1 windows ( width = , h e i g h t = )
pdf() ,postscript() , png() ,jpeg() ,pictex()

1 ## s t a r t a PDF f i l e
pdf ( p i c t u r e . pdf , h e i g h t =4, width =6)
3 ## your drawing commands h e r e
dev . o f f ( ) ### c l o s e t h e PDF f i l e

dev . copy ( d e v i c e , f i l e = , h e i g h t , width )

103.

28

1 # two d i m e n s i o n s
n < 100
3 x < cumsum ( rnorm ( n ) )
y < cumsum ( rnorm ( n ) )
5 p l o t ( x , y , type = l )

104.
curve(expr, from , to, add = T)
spline(x , y , n= )
1 x < 1 : 5
y < c ( 1 , 3 , 4 , 2 . 5 , 2 )
3 plot (x , y)
sp < s p l i n e ( x , y , n = 5 0 )
5 l i n e s ( sp )

105. (lattice)
lattice S-plus Trellis R



1 library ( lattice )
h i s t o g r a m ( ~ h e i g h t | v o i c e . part , data = s i n g e r )
lattice

lattice

xyplot(yx)
dotplot(yx) Cleveland ()
barchart(yx) y x
stripplot(yx) x y
bwplot(yx)
histogram(x)

lattice Hadley Wickham ggplot2 Grammar of Graphics


base lattice http://had.co.nz/

29
ggplot2/

106.
persp() contour()
18 outer()

107.
image() lled.contour()
x < y < s e q ( 10 , 1 0 , l e n g t h =50)
2 f < f u n c t i o n ( x , y ) {
r < s q r t ( x^2 + y ^2)
4 10 * s i n ( r ) / r
}
6 z < o u t e r ( x , y , f )
image ( x , y , z )
8 f i l l e d . contour ( x , y , z )

108.
R R
x < 1 : 1 0
2 y < r u n i f ( 1 0 )
symbols ( x , y , c i r c l e s = y/ 2 , i n c h e s = F , bg = x )

109. QQ
apply() R
1 t a b l e < data . frame ( x1 = rnorm ( 1 0 0 ) , x2 = rnorm ( 1 0 0 , 1 , 1 ) )
par ( ask = TRUE) # wait f o r changing
3 r e s u l t s = apply ( t a b l e , 2 , qqnorm )
par ( ask = FALSE)

110.
par()
x < rnorm ( 1 0 0 )
2 hist (x)
op < par ( f i g=c ( . 0 2 , . 5 , . 5 , . 9 8 ) , new=TRUE)
4 boxplot (x)

30
111. R
?plotmath LATEX

x < 1 : 1 0 ; p l o t ( x , type = n )
2 t e x t ( 3 , 2 , e x p r e s s i o n ( p a s t e ( Temperature ( , d e g r e e , C) i n 2003 ) ) )
t e x t ( 4 , 4 , e x p r e s s i o n ( bar ( x ) == sum ( f r a c ( x [ i ] , n ) , i ==1, n ) ) )
4 t e x t ( 6 , 6 , e x p r e s s i o n ( hat ( b e t a ) == (X^ t * X) ^ { . 1 } * X^ t * y ) )
t e x t ( 8 , 8 , e x p r e s s i o n ( z [ i ] == s q r t ( x [ i ] ^ 2 + y [ i ] ^ 2 ) ) )

112. bar
barplot() rect()

1 x < 1 : 1 0 ; names ( x ) < l e t t e r s [ 1 : 1 0 ]


b < b a r p l o t ( x , c o l = r e v ( h e a t . c o l o r s ( 1 0 ) ) )
3 t e x t ( b , x , l a b e l s = x , pos = 3 )

113.

x y
( )2 + ( )2 = 1 = x = a sin , y = b cos , 0 < < 2
a b

1 t < s e q ( 0 , 2 * pi , l e n g t h = 1 0 0 )
x < s i n ( t ) # a=1
3 y < 2* c o s ( t ) # b=2
p l o t ( x , y , type = l )

114. word R
epspdfpngjpgti word
eps

115.
FBasics

skewness ( )
2 kurtosis ()

31

116.
table() table(x) x table(x,y)
x < with ( a i r q u a l i t y , t a b l e ( c u t (Temp , q u a n t i l e (Temp ) ) , Month ) )
2 prop . t a b l e ( x , 1 )

117.

yi = + xi + i


lm()
lm . s w i s s < lm ( F e r t i l i t y ~ . , data = s w i s s )
lm()
coecients
residuals
tted.values

:
1 names ( lm . s w i s s )
summary() anova()
1 # t h e same a s summary . lm ( )
summary ( lm . s w i s s )
3 anova ( lm . s w i s s )
R-intro Statistical models in R
biglm biglm()

118.
update()
1 summary ( f 0 < lm ( F e r t i l i t y ~ . , data = s w i s s ) )
f 1 < update ( f0 , . ~ . Examination )
3 summary ( f 1 )

32
119.
R step() AIC
AIC

1 u t i l s : : example ( lm )
s t e p ( lm . D9)

step both,forward,backward backward


add1drop1

120. R (Quantile Regression)


quantreg quantregForest

data ( e n g e l )
2 p l o t ( l o g 1 0 ( f o o d e x p ) ~ l o g 1 0 ( income ) , data = e n g e l ,
main = e n g e l data ( l o g 1 0 t r a n s f o r m e d ) )
4 t a u s < c ( . 1 5 , . 2 5 , . 5 0 , . 7 5 , . 9 5 , . 9 9 )
r q s < a s . l i s t ( t a u s )
6 f o r ( i in seq ( along = taus ) ) {
r q s [ [ i ] ] < rq ( l o g 1 0 ( f o o d e x p ) ~ l o g 1 0 ( income ) ,
8 tau = t a u s [ i ] , data = e n g e l )
l i n e s ( l o g 1 0 ( e n g e l $ income ) , f i t t e d ( r q s [ [ i ] ] ) , c o l = i +1) }
10 l e g e n d ( b o t t o m r i g h t , p a s t e ( tau = , t a u s ) , i n s e t = . 0 4 ,
c o l = 2 : ( l e n g t h ( t a u s )+1) , l t y =1)

121.
t.test()

1 x < rnorm ( 1 0 0 )
t . test (x)

122.
K (kmeans() )

x < r b i n d ( matrix ( rnorm ( 1 0 0 , sd = 0 . 3 ) , n c o l = 2 ) ,


2 matrix ( rnorm ( 1 0 0 , mean = 1 , sd = 0 . 3 ) , n c o l = 2 ) )
c l < kmeans ( x , 2 , 2 0 )
4 p l o t ( x , c o l = c l $ c l u s t e r , pch =3, lwd=1)
p o i n t s ( c l $ c e n t e r s , c o l = 1 : 2 , pch = 7 , lwd=3)
6 segments ( x [ c l $ c l u s t e r = = 1 , ] [ , 1 ] , x [ c l $ c l u s t e r = = 1 , ] [ , 2 ] ,

33
cl $ centers [1 ,1] , cl $ centers [1 ,2])
8 segments ( x [ c l $ c l u s t e r = = 2 , ] [ , 1 ] , x [ c l $ c l u s t e r = = 2 , ] [ , 2 ] ,
cl $ centers [2 ,1] , cl $ centers [2 ,2] ,
10 c o l =2)

(hclust() )

n < s e q ( 1 , 5 0 , by = 4 )
2 ( x < USArrests [ n , ] ) # p r i n t ( )
hc1 < h c l u s t ( d i s t ( x ) , method = c o m p l e t e )
4 hc2 < h c l u s t ( d i s t ( s c a l e ( x ) ) , method = c o m p l e t e )
hc3 < h c l u s t ( d i s t ( x ) , method = ave )
6 l a y o u t ( matrix ( c ( 1 , 1 , 2 , 3 ) , nrow = 2 , byrow = T) )
p l o t ( hc1 ) ; p l o t ( hc2 ) ; p l o t ( hc3 )

cutree()

1 c u t r e e ( hc , k = 1 : 3 )

cluster

1 library ( cluster )
c l u s p l o t ( x , pam( x , 2 ) $ c l u s t e r i n g )

123.
stats princomp prcomp

( pc . c r < princomp ( USArrests , c o r = TRUE) )


2 p l o t ( pc . c r , type = l i n e s # o r b a r p l o t
) # or s c r e e p l o t
4 l o a d i n g s ( pc . c r )

princomp() cor = TRUE


loadings() screeplot()

124.
R factanal()

example ( f a c t a n a l )

125.
shapiro.test() ks.test()(Kolmogorov-Smirnov ) jarque.bera.test()

34
( tseries ) normtest fBasics

126. t
t.test() paired

1 require ( stats )
## Student s p a i r e d tt e s t
3 t . t e s t ( e x t r a ~ group , data = s l e e p , p a i r e d = TRUE)

SPSS

extra group
0.7 1
-0.6 1

4.6 2
3.4 2

1 ap ro p o s ( t e s t )

bartlett.test binom.test
chisq.test 2 cor.test
sher.test Fisher friedman.test Friedman
kruskal.test Kruskal-Wallis mcnemar.test McNemar
pairwise.t.test PP.test Phillips-Perron
var.test wilcox.test Wilcoxon

127. R
sem

128.
I()

1 lm ( y ~ x + I ( x ^2) + I ( x ^ 3 ) )

35
129. ANOVA

aov()


aov(x a)
aov(x a + b)
aov(x a + b +a:b)
aov(x a*b)

130.
0

1 r e s u l t < lm ( smokes ~ 0 + male + f e m a l e , data = smokerdata )

131.
conntglm nls MASS connt.glm connt.nls

1 f i t < lm ( 1 0 0 /mpg ~ d i s p + hp + wt + am, data = mtcars )


confint ( f i t )
3 c o n f i n t ( f i t , wt )

132.
MASS lm.ridge()

1 data ( l o n g l e y ) # not t h e same a s t h e SPLUS d a t a s e t


names ( l o n g l e y ) [ 1 ] < y
3 lm . r i d g e ( y ~ . , l o n g l e y )
p l o t ( lm . r i d g e ( y ~ . , l o n g l e y ,
5 lambda = s e q ( 0 , 0 . 1 , 0 . 0 0 1 ) ) )
s e l e c t ( lm . r i d g e ( y ~ . , l o n g l e y ,
7 lambda = s e q ( 0 , 0 . 1 , 0 . 0 0 0 1 ) ) )

Regularized and Shrinkage Methods R


133. logistic
logistic 01
glm()

36


Gaussiana E(y) = xT
exp (xT )
Binomial E(y) = 1+exp (xT )
Logistic probit
Poission E(y) = exp (xT )
a
Normal

1 f i t 1 < glm ( formula , f a m i l y = g a u s s i a n , data )

1 f i t 1 < lm ( formula , data )

134.

yi = 0 + 1 xi + 2 x2i + . . . + k xki , i = 1, 2, . . . , n,

k x, x2 , . . . , xk
R poly()

1 ( z < p o l y ( 1 : 1 0 , 3 ) )

135.
hat(),hatvalues()

136. D-W
car durbin.watson lmtest dwtest

1 h e l p . s e a r c h ( DurbinWatson )

137. Spearman kendall


cor() Person method Kendall
Spearman

1 c o r ( l o n g l e y , method = spearman )

37

Pearson
Kendall
Spearman

138. Decision Tree


Tree-based model
Modern Applied Statistics With S rpart

1 library ( rpart )
set . seed (123)
3 cpus . rp < r p a r t ( l o g 1 0 ( p e r f ) ~ . , cpus [ , 2 : 8 ] , cp = 1 e 3)
p l o t ( cpus . rp , uniform = T)
5 t e x t ( cpus . rp , d i g i t s = 3 )

R R

139.
t 0 2 q


q
Xt = j tj
0

p

p
Xt = i Xti + t
1

ARM A(p, q)

p
q
Xt = i Xti + j tj
1 0

arma arima arima R

arima(x,order = c(0,0,0),seasonal = list(order = c(0, 0, 0))

1 require ( graphics )
( f i t 1 < arima ( p r e s i d e n t s , c ( 1 , 0 , 0 ) ) )
3 tsdiag ( f i t 1 )

38
140. box-cox
MASS

1 boxcox ( )

141. Breusch-Pagan
lmtest bptest() car ncv.test()

142.
MASS lda() Fisher Linear Discriminant Analysis qda()

143. OLS ?
qr.solve()

1 qr . s o l v e (X, y )

(X X)1 X y

144.
R cancor()

1 pop < L i f e C y c l e S a v i n g s [ , 2 : 3 ]
o e c < L i f e C y c l e S a v i n g s [ , ( 2 : 3 ) ]
3 c a n c o r ( pop , o e c )

145. R
survival Kaplan-Meier

1 # f i t a KaplanMeier and p l o t i t
f i t < s u r v f i t ( Surv ( time , s t a t u s ) ~ x , data=aml )
3 plot ( f i t )
# l i f e table
5 c b i n d ( f i t $ time , f i t $n . r i s k , f i t $n . event , f i t $ s u r v )

survt type kaplan-meier,eming-harrington, fh2



COX

1 ## F i t a time t r a n s f o r m model u s i n g c u r r e n t age


coxph ( Surv ( time , s t a t u s ) ~ ph . e c o g + t t ( age ) , data=lung ,

39
3 tt = function (x , t , . . . ) pspline (x + t/ 365.25))

146. R

R parallel

1 library ( parallel )
d o i t < f u n c t i o n ( x ) ( x )^2 + 2 *x
3 system . time ( r e s < l a p p l y ( 1 : 5 0 0 0 0 0 0 , d o i t ) )
rm( r e s )
5 gc ( )
c l < makeCluster ( g e t O p t i o n ( c l . c o r e s , 3 ) )
7 system . time ( r e s < parLapply ( c l , 1 : 5 0 0 0 0 0 0 , d o i t ) )
stopCluster ( cl )

147. R SPSS
Rcmdr

Commander ( )


car eects abindlmtestmultcomprelimpRODBCrgl
rattle

148.
system.time() proc.time() R system.time()
proc.time()
system.time()
Sys.time()

149. R
R maps mapdata mapdata

1 l i b r a r y ( mapdata )
map( c h i n a )

40

map
map( s t a t e )

maptools
PBSmapping, spatstat, maps, RArcInfo, Stata tmap, WinBUGS, Mondrian

150. R

1 gc ( )
R R
gc()

151. IDE()

Windows Linux Vi

R

R IDE

ESS All Emacs Speaks Statistics no
RStudio All yes
UltraEdit All no
Eclipse All StatET Eclipse no

Notepad++ Windows NpptoR R no
Tinn-R Windows R Console no
RWinEdt Windows WinEdt no

RStudio R
RStudio

152. Sweave
Sweave TEX S Sweave
TEX S

41
TEX
S
S
Sweave User ManualASweave

Sweave(in R) LAT X
Sweave TEX E pdf
dvipdfmx
knitr knitr

42
A Sweave
\documentclass[CJK]{cctart}
\usepackage{verbatim}
\title{Sweave }
\author{}
\date{}
\SweaveOpts{echo=FALSE}

\begin{document}

\maketitle

Sweave \LaTeX{} R
\LaTeX{}

\LaTeX{}
R $<<>>=$ $@$
echofig, R
\LaTeX{} \LaTeX{}
R \LaTeX{}

t
<<echo = TRUE>>=
require(stats)
## Student's paired t-test
m <- t.test(extra ~ group, data = sleep, paired = TRUE)
print(m)
@
R
\texttt{sleep}t
$p$-value\Sexpr{format.pval(m$p.value)}

<<echo=TRUE,results=hide>>=
choose(49,6)
@
\Sexpr{choose(49,6)}

43
``'' word

Sweave R \LaTeX{}
\LaTeX{} \footnote{Sweave ps pdf }
Titanic

<<fig=TRUE,echo=FALSE>>=
require(graphics)
mosaicplot(Titanic, main = "Survival on the Titanic")
@

\end{document}

Copyright 2012 R and all the Contributors to R FAQ. All rights reserved.
R R FAQ 2012
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free
Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with
the Invariant Sections being Contributors, no Front-Cover Texts, and no Back-Cover Texts.
GNU 1.2
Invariant Sections Contributors Front-Cover Texts Back-Cover Texts

44
Index

Symbols citation . . . . . . . . . . . . . . . . . . . . . 3 dwtest . . . . . . . . . . . . . . . . . . . . . 37


\\ . . . . . . . . . . . . . . . . . . . . . . . . . 11 clipboard . . . . . . . . . . . . . . . . . . 10
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 cm.colors . . . . . . . . . . . . . . . . . . 28 E
.GlobalEnv . . . . . . . . . . . . . . . . 12 col . . . . . . . . . . . . . . . . . . . . . . . . . 27 edit . . . . . . . . . . . . . . . . . . . . . . . . 10
.packages . . . . . . . . . . . . . . . . . . . 6 col2rgb . . . . . . . . . . . . . . . . . . . . 28 eigen. . . . . . . . . . . . . . . . . . . . . . . 18
/. . . . . . . . . . . . . . . . . . . . . . . . . . .11 colMeans . . . . . . . . . . . . . . . . . . 19 ESS. . . . . . . . . . . . . . . . . . . . . . . .41
%*% . . . . . . . . . . . . . . . . . . . . . . . 18 colors . . . . . . . . . . . . . . . . . . . . . . 27 eval . . . . . . . . . . . . . . . . . . . . . . . . 12
. . . . . . . . . . . . . . . . . . . . . . . 19, 35 combn . . . . . . . . . . . . . . . . . . . . . 19
{} . . . . . . . . . . . . . . . . . . . . . . . . . 14 Commander. . . . . . . . . . . . . . . .40 F
complex . . . . . . . . . . . . . . . . . . . 18 factanal . . . . . . . . . . . . . . . . . . . . 34
A
connt . . . . . . . . . . . . . . . . . . . . . 36 factorial . . . . . . . . . . . . . . . . . . . 19
abline . . . . . . . . . . . . . . . . . . . . . . 24
connt.glm. . . . . . . . . . . . . . . . . 36 FALSE . . . . . . . . . . . . . . . . . . . . 14
aggregate . . . . . . . . . . . . . . . . . . 15
connt.nls . . . . . . . . . . . . . . . . . 36 le.choose . . . . . . . . . . . . . . . . . . 11
any . . . . . . . . . . . . . . . . . . . . . . . . 13
contour . . . . . . . . . . . . . . . . . . . . 30 lled.contour . . . . . . . . . . . . . . . 30
aov . . . . . . . . . . . . . . . . . . . . . . . . 36
crossprod . . . . . . . . . . . . . . . . . . 18 vnum . . . . . . . . . . . . . . . . . . . . . 17
aperm . . . . . . . . . . . . . . . . . . . . . 14
cumsum . . . . . . . . . . . . . . . . 14, 29 x . . . . . . . . . . . . . . . . . . . . . . . . . 10
append . . . . . . . . . . . . . . . . . . . . 12
curve . . . . . . . . . . . . . . . . . . . . . . 29 format . . . . . . . . . . . . . . . . . . . . . 22
apply . . . . . . . . . . . . . . . 14, 19, 30
cutree. . . . . . . . . . . . . . . . . . . . . .34
as.Date . . . . . . . . . . . . . . . . . . . . 22 G
as.numeric . . . . . . . . . . . . . . . . . 25 D gc . . . . . . . . . . . . . . . . . . . . . . . . . 41
as.POSIXct . . . . . . . . . . . . . . . . 22 D . . . . . . . . . . . . . . . . . . . . . . . . . . 19 getAnywhere . . . . . . . . . . . . . . . . 8
axes . . . . . . . . . . . . . . . . . . . . . . . 25 data . . . . . . . . . . . . . . . . . . . . . . . . 7 getwd . . . . . . . . . . . . . . . . . . . . . . . 6
axis . . . . . . . . . . . . . . . . . . . . . . . . 25 data frame . . . . . . . . . . . . . . 7, 14 glm . . . . . . . . . . . . . . . . . . . . . . . . 36
demo . . . . . . . . . . . . . . . . . . . . . . . 3 gray . . . . . . . . . . . . . . . . . . . . . . . 28
B
detach . . . . . . . . . . . . . . . . . . . . . . 6 grep . . . . . . . . . . . . . . . . . . . . . . . 21
barplot . . . . . . . . . . . . . . . . . 27, 28
dev.copy . . . . . . . . . . . . . . . . . . . 28 grey . . . . . . . . . . . . . . . . . . . . . . . 28
boxcox . . . . . . . . . . . . . . . . . . . . . 39
dev.cur . . . . . . . . . . . . . . . . . . . . 27 grid . . . . . . . . . . . . . . . . . . . . . . . . 26
bptest . . . . . . . . . . . . . . . . . . . . . 39
dev.list . . . . . . . . . . . . . . . . . . . . 27
Breusch-Pagan . . . . . . . . . . . . . 39
dev.o . . . . . . . . . . . . . . . . . . . . . 27 H
C dev.set . . . . . . . . . . . . . . . . . . . . . 27 hat,hatvalues . . . . . . . . . . . . . . 37
cancor . . . . . . . . . . . . . . . . . . . . . 39 Devices . . . . . . . . . . . . . . . . . . . . 26 hclust . . . . . . . . . . . . . . . . . . . . . . 34
capture.output . . . . . . . . . . . . . . 9 diag . . . . . . . . . . . . . . . . . . . . . . . 18 head . . . . . . . . . . . . . . . . . . . . . . . . 8
car . . . . . . . . . . . . . . . . . . . . . . 8, 39 ditime . . . . . . . . . . . . . . . . . . . . 22 heat.colors . . . . . . . . . . . . . . . . . 28
casefold . . . . . . . . . . . . . . . . . . . . 21 duplicated . . . . . . . . . . . . . . . . . 13 help . . . . . . . . . . . . . . . . . . . . . . . . . 4
choose . . . . . . . . . . . . . . . . . . . . . 19 durbin.watson. . . . . . . . . . . . . .37 help.search . . . . . . . . . . . . . . . . . . 4

45
I mar . . . . . . . . . . . . . . . . . . . . . . . . 23 png . . . . . . . . . . . . . . . . . . . . . . . . 28
I . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 matrix . . . . . . . . . . . . . . . . . 14, 19 points. . . . . . . . . . . . . . . . . . . . . .23
identical . . . . . . . . . . . . . . . . . . . 13 memory.limit . . . . . . . . . . . . . . . . 4 poly . . . . . . . . . . . . . . . . . . . . . . . 37
if . . . . . . . . . . . . . . . . . . . . . . . . . . 14 merge . . . . . . . . . . . . . . . . . . . . . . 16 postscript . . . . . . . . . . . . . . . . . . 28
image . . . . . . . . . . . . . . . . . . . . . . 30 methods . . . . . . . . . . . . . . . . . . . . 8 princomp . . . . . . . . . . . . . . . . . . 34
integer . . . . . . . . . . . . . . . . . . . . . 17 print . . . . . . . . . . . . . . . . . . . . . . . 10
N
integrate . . . . . . . . . . . . . . . . . . . 17 proc.time . . . . . . . . . . . . . . . . . . 40
nchar . . . . . . . . . . . . . . . . . . . . . . 22
iris. . . . . . . . . . . . . . . . . . . . . . . . . 25 prompt . . . . . . . . . . . . . . . . . . . . . 5
ncv.test . . . . . . . . . . . . . . . . . . . . 39
is.na . . . . . . . . . . . . . . . . . . . . . . . 12
NULL . . . . . . . . . . . . . . . . . . . . . 14 Q
J qda . . . . . . . . . . . . . . . . . . . . . . . . 39
jarque.bera.test . . . . . . . . . . . . 35 O
qqnorm . . . . . . . . . . . . . . . . . . . . 30
jpeg . . . . . . . . . . . . . . . . . . . . . . . 28 optimize . . . . . . . . . . . . . . . . . . . 20
qr.solve . . . . . . . . . . . . . . . . . . . . 39
options. . . . . . . . . . . . . . . . . . . . . .5
K Quantile Regression . . . . . . . . 33
outer . . . . . . . . . . . . . . . . . . . . . . 18
kmeans . . . . . . . . . . . . . . . . . . . . 33 R
knitr . . . . . . . . . . . . . . . . . . . . . . . 42 P
rainbow . . . . . . . . . . . . . . . . . . . . 28
ks.test . . . . . . . . . . . . . . . . . . . . . 34 Package . . . . . . . . . . . . . . . . . . . . . 6
rattle . . . . . . . . . . . . . . . . . . . . . . 40
cluster . . . . . . . . . . . . . . . . . 34
L read.table . . . . . . . . . . . . . . . . . . 10
plotrix . . . . . . . . . . . . . . . . . 25
latex . . . . . . . . . . . . . . . . . . . . . . . 10 read.xls . . . . . . . . . . . . . . . . . . . . . 9
Rcmdr . . . . . . . . . . . . . . . . . 40
latex.table . . . . . . . . . . . . . . . . . 10 rect . . . . . . . . . . . . . . . . . . . . . . . . 31
rpart . . . . . . . . . . . . . . . . . . 38
layout. . . . . . . . . . . . . . . . . . . . . .23 Regular Expressions . . . . 14, 21
sem . . . . . . . . . . . . . . . . . . . . 35
lda . . . . . . . . . . . . . . . . . . . . . . . . . 39 rev. . . . . . . . . . . . . . . . . . . . . . . . .14
stats . . . . . . . . . . . . . . . . . . . 34
legend . . . . . . . . . . . . . . . . . . . . . 25 rgb . . . . . . . . . . . . . . . . . . . . . . . . 27
tseries . . . . . . . . . . . . . . . . . 35
letters . . . . . . . . . . . . . . . . . . . . . 28 rm . . . . . . . . . . . . . . . . . . . . . . . . . . 5
par . . . . . . . . . . . . . . . . . 23, 25, 30
Library . . . . . . . . . . . . . . . . . . . . . 6 RMySQL . . . . . . . . . . . . . . . . . . 11
parallel . . . . . . . . . . . . . . . . . . . . 40
library . . . . . . . . . . . . . . . . . . . . 5, 6 rnorm . . . . . . . . . . . . . . 20, 25, 29
parplot . . . . . . . . . . . . . . . . . . . . 31
lines . . . . . . . . . . . . . . . . . . . . . . . 29 RODBC . . . . . . . . . . . . . . . . . . . 11
parse . . . . . . . . . . . . . . . . . . . . . . 12
list . . . . . . . . . . . . . . . . . . . . . . . . . . 5 rowMeans . . . . . . . . . . . . . . . . . . 19
paste . . . . . . . . . . . . . . . . . . . . 5, 21
lm . . . . . . . . . . . . . . . . . . . . . . . . . 36 RSiteSearch . . . . . . . . . . . . . . . . . 4
pch . . . . . . . . . . . . . . . . . . . . . . . . 25
lm.ridge. . . . . . . . . . . . . . . . . . . .36
pdf . . . . . . . . . . . . . . . . . . . . . . . . 28 S
lmtest. . . . . . . . . . . . . . . . . . . . . .39
persp . . . . . . . . . . . . . . . . . . . . . . 30 sample . . . . . . . . . . . . . . . . . . . . . 15
loadings. . . . . . . . . . . . . . . . . . . .34
pictex . . . . . . . . . . . . . . . . . . . . . . 28 sapply . . . . . . . . . . . . . . . . . . . . . 15
lower.tri . . . . . . . . . . . . . . . . . . . 19
pie . . . . . . . . . . . . . . . . . . . . . . . . . 25 save . . . . . . . . . . . . . . . . . . . . . . . . . 6
ls . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
plotmath. . . . . . . . . . . . . . . . . . .31 save.image . . . . . . . . . . . . . . . . . . 6
M pmax . . . . . . . . . . . . . . . . . . . . . . 14 savePlot . . . . . . . . . . . . . . . . . . . 28
mai . . . . . . . . . . . . . . . . . . . . . . . . 23 pmin . . . . . . . . . . . . . . . . . . . . . . . 14 scale . . . . . . . . . . . . . . . . . . . . . . . 16

46
screeplot . . . . . . . . . . . . . . . . . . . 34 step . . . . . . . . . . . . . . . . . . . . . . . . 33 toupper . . . . . . . . . . . . . . . . . . . . 21
search . . . . . . . . . . . . . . . . . . . . . . . 6 strwrap . . . . . . . . . . . . . . . . . . . . 26 transform . . . . . . . . . . . . . . . . . . 14
setwd . . . . . . . . . . . . . . . . . . . . . . . 6 subset . . . . . . . . . . . . . . . . . . . . . 12 twoord.plot . . . . . . . . . . . . . . . . 25
shapiro.test . . . . . . . . . . . . . . . . 34 substr. . . . . . . . . . . . . . . . . . . . . .21
shell.exec . . . . . . . . . . . . . . . . . . . 5 survt . . . . . . . . . . . . . . . . . . . . . 39 U
show.error.messages . . . . . . . . 5 Sweave. . . . . . . . . . . . . . . . . . . . .41 unique . . . . . . . . . . . . . . . . . . . . . 13
uniroot . . . . . . . . . . . . . . . . . . . . 20
sink . . . . . . . . . . . . . . . . . . . . . 9, 10 system . . . . . . . . . . . . . . . . . . . . . . 5
update . . . . . . . . . . . . . . . . . . . . . 32
solve . . . . . . . . . . . . . . . . . . . . . . . 18 system.time . . . . . . . . . . . . 19, 40
update.packages. . . . . . . . . . . . .5
some . . . . . . . . . . . . . . . . . . . . . . . . 8 T
upper.tri . . . . . . . . . . . . . . . . . . . 19
sort . . . . . . . . . . . . . . . . . . . . . . . . 25 t . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
source . . . . . . . . . . . . . . . . . . . . . 10 t.test . . . . . . . . . . . . . . . . . . . . . . 33 W
spline . . . . . . . . . . . . . . . . . . . . . . 29 table . . . . . . . . . . . . . . . . . . . . . . . 32 windows . . . . . . . . . . . . . . . . . . . 28
split.screen . . . . . . . . . . . . . . . . . 23 tail . . . . . . . . . . . . . . . . . . . . . . . . . 8 with . . . . . . . . . . . . . . . . . . . . . . . 25
sqldf . . . . . . . . . . . . . . . . . . . . . . . 19 tapply . . . . . . . . . . . . . . . . . . . . . 15
sqrt . . . . . . . . . . . . . . . . . . . . . . . . 19 terrain.colors . . . . . . . . . . . . . . . 28 X
stars . . . . . . . . . . . . . . . . . . . . . . . 27 tolower . . . . . . . . . . . . . . . . . . . . 21 xlsReadWrite . . . . . . . . . . . . . . . 9
stem . . . . . . . . . . . . . . . . . . . . . . . 25 topo.colors . . . . . . . . . . . . . . . . . 28 xtable. . . . . . . . . . . . . . . . . . . . . .10

47