Rènù53s
Rfrequentlyaskedquestions
http://www.r-project.org
153sòD?R
ThisdocumentisgeneratedfromLATEXsourcescompiledwithctexv0.7d
inaWindowsplatform.TheusedpackagesareCJKalistingsagraphicxandsoon.
?
?éó?=?¥ ?÷";μ ?1?R2Zó? ?RintroRdataRadmin9μ ?
1?o ó?¥contributeddocuments?μ?? ?1?CapitalOfStatistics ?¥) ?ù5b
''ó?¥"¥ ^1 μB?d9
?D?¥RèqD?4B? y ?a MRèq¥ü
??TFíN? V???¥??VriPùb?éó?×??d9ZE yN ?
ù5? V?WD?d9D¥ ??? M?b
R ^B???v¥8"CRAN¥TaskViews V[b#1 A?= ?wa ?sa
Da bWd9a×rd9?ZE¥o b7?tZE?YVM?¥RPackages ?Z V[ a
DR ^Bq àμDh¥ Yfb
?TF¥?ó àù5 1úB''1?R¥e? ?!9 ^B??p¥ê4??? 7
hèè?|?heb??z37:¥ó?Fa MaDR ^??p¥úùb
> ±+!1
June25,2008
á?
abel,cran,rtist,XieYihui,zhangv...
1sunbjtgmail.com
xA-y
1.R ^S I 1¥$
R ^B?μ"d9s??#<vTm??¥èq"d ^?í X §vDd9D"¥RossIhaka?
RobertGentleman]7 ?b??R sBecker,Chambers&Wilks7 ?¥S?Sussman¥Scheme
??y¥?Y ?[R A ??S?ydèM ?b
2.'' ú V[/R¥? ??
R¥2Z?? ê4?_?^http://cran.r-project.org/mirrors.html1?UC
Berkeley/èq?''bR?μLinuxMacOSXWindowsü ?/¥ò??''?T ^Windows
¨?é??^?_ê4Windows(95andlater)é?base/R-x.x.x-win32.exeb
3.1 I 1R?SR
?s ^y1 êR¥T?(RobertGentleman?RossIhaka)¥??s ^ s? : L iS
?y¥?Y ?1S?y¥Zyb
4.CRAN ^ I 1i ±$
CRAN ^ComprehensiveRArchiveNetwork¥e ^?μ]B'' ?R¥???''
ó??÷} ?¥? ?"?b
5.á ^? má?? 7 SDR
R¥2Z?:?μv ?óD''÷? V[? Ihttp://cran.r-project.org/other-docs.
html ¥?óJró?bd9-?bbs ^B??p¥DR¥?ó?_?? ? F V[s?
v D'' °¤4ù5]vE)b
6.D?R1?? ¥R-introü V[
1$
R-intro? L ^2Zó??K$¥? ?? ^VRèq?¨??¥#i? a??RD?b
V[? IR-intro? ? ??a2?sT1$Db
7.? BtR¥ü? ?" 1$
??vE?¨R¥V?? A?v?sü?¥R ?!?1?ó
ModernAppliedStatisticswithS VenablesandRipley
TheNewSLanguage:AProgrammingEnvironmentforDataAnalysisandGraphics
| RichardA.BeckerJohnM.ChambersAllanR.Wilks
AHandbookofStatisticalAnalysisUsingR BrianS.EverittTorstenHothorn
DataAnalysisandGraphicsusingR MaindonaldandBraun
IntroductoryStatisticswithR Dalgaard
8.R31I? 1$
2
?v ? H??31y1Rμ?f ??7O ???9FF¨¥B?ZE?f ?? V
[R1{?s?b
9.??e? B?R¥ è0$
3?100?ú ? ? ?s? ? ?i?100? ?é?+? í ?b
1x mean(x)
3sd(x)
summary(x)
??F? V[ P¨demo()f ?1?R?
¥m? U
demo(graphics)
10.R31?¨n¨ 1$
?31R ^B {GNUGeneralPublicLicense(GPL)/??¥ 7÷èqo ^? B?s?
?¨? <¨ob???1 I 1μtn Han ?ONì?c¥ <d9èq ?? 3i$
11.1 I 1R?? P¨?V50%¥CPU$
? ^Windows/?5 ?¥? ?|?CPU AT ^??CPU] H9 ? P¨1 èb7R
^?L?9 ?èq ???] H P¨2?[ ¥CPUb?F¥9 ??¨¥ ^ ??/ ?F??
CCPU?¨??ì50% b
12.?????t ú?¨R
?TF ^LATEX¨? V[R? P¨ 7citation()¤? VBibTEX P¨¥=?? ^B
?¥?¨
1citation(package=’package’)
xB$? M
13.??¤úù$
R¥úù"ddè<v V[°¤ P¨\?topic"help(topic) ?|topic¥úù?9 V P¨
help.search("topic") ? ? ìúù"db
?TFo??f ?¥?s? 1 V[ P¨apropos("tab") ? ? ì¤??=i ?μc
tab3 ¥f ?b
?T? àμ¤?31¥'' ?μRSiteSearchhttp://finzi.psych.upenn.edu/search.
html?N?Rü ?
P¨RSiteSearch()f ?b
14.R V P¨¥Kv=i ^ $
3
Rüèy1Vsh{=i7 s?·37 Y L9? ^?Nb?V?zá ì P¨¥ ? Yè? ^
?vYèR? V[) ?b+?Hq/á ì V?31÷v¥=i ?S ?4 ?o? ? !?
9v=i
??Ré?-9FR?? ?bCMDìa/?9F? ?¥Rterm
1r??max?mem?size=1Gb
YV@FRHOME/binà"dìa?°¤\?"??2
1rgui??max?mem?size=1Gb
??Ré?aYVmemory.limitf ?9vRé?¥=iK?b
R¥yT=ivl¥ !?′132Mb?3GbW¥?i ?′b?314 U¥ ^Windowsü ? V¨
Kvμr=i12Gb9ü ^ a L= R¥yT=iuW132Mbà2Gbb
15.1 I 1help.search() ? ì?? P¨$
?í ?¥ ? ì?c1p??? ???JavaOJava?Javascript?3?í ?b
16.R|??ó 1$
|???zR?v?s¥T?? ^[?ó1?¥???ó3? I n t#yp
P¨??óìab
17.R|?1??? Tabcompletion 1$
|?2.5.0?''?R??
71????? P¨Tabo?1???R 7 P¨?=
QTabaRí ?μ V?¥?? 7 Vb
18.??b"M $
b"??M
P¨rm()f ?b"=i? ?μ¥M
1rm(list=ls(all=TRUE))
19.??÷?l ??aA U ?3ê ?$
options(digits=)digitsa ?¥? ?11à22¥ ?3a17boptionsf ?? V[?M??
ê[?÷?4 U?(prompt) ^?A Up?(show.error.messages)?b
20.???¨"d=¥??$
P¨system()f ?¨shell.exec()?¨M??? ?u 7óq:
1#gotothecran
system(paste(’"C:/ProgramFiles/InternetExplorer/iexplore.exe"’,
2]"|?Rterm
4
3’cran.r-project.org’),wait=FALSE)
#invokethenotepad
5system("notepad")
shell.exec("C:/WINDOWS/clock")
21.Windows/ 6)R??X× packages$
e" c/? R|??'' =¥library" c/¥óq Jà??''library" c/?a
update.packages()?RüR ??¥" c/?aupdate.packages()b
22.???X? ¥packages$
? I
remove.packages(c("pkg1","pkg2"),
2lib=file.path("path","to","library"))
23.R¥yT" c'' ú$
B?¥WindowsXP/¥RyT" c
C:nDocumentsandSettingsnusername
? P¨getwd() 7¤R¥yT" c(WorkingDirectory) P¨setwd() !?yT" cê?b
24.á8"i1-¥yT$
P¨save.image()f ?b ?|R¥ S" ci:ku workingspaceà.RDataóq? P
¨save(...,flle=)i31i¥R`b
25.R??? $
YVê4/?^R V[1?? ?? ''1¥??9 V[V?^?_/ V¨¥°
¤''1? 3b
26.library()¥I_?T ^ I 1$
?Fa31s ?R] H V[ P¨
1detach("package:pkg")
27.Library?Packageμ I 1uY$
? ?àQ¥??^jy1R?FPackage¥ 7 ^LibraryLibrary ^B?" c V?
cB??Package7Package ^cf ?a ? a m¨¥B?"? ???Library''
Windows/¥\.zip"óqb
28.??¤?FPackage¥ V$
3RμUnixaMacaWindows???''?i9sY????''
5
search()f ?Rí?-F¥¥f ? P¨
1.packages(all.available=TRUE)
7¤''1? ¥ Vb
?R?aR=i??1?F??Package
R S ?? V
í ?
statsè¨d9f ?
graphics$?mf ?
grDevices$gridm? !!
utilsRy f ?
datasets$ ? "
methods¨?R`?I?y ¥ZE? ?¥?l
base$f ?
29.?? P¨R=?¥ ? "$
Rdatasets?4 100? V[ P¨¥ ? "?t ? "? V[YVdata()f ?F?
=ib
1dim(data()$results)
data()$results[,4]
30.R¥ ? ??μ+?$
R S?y àμS
?YV P¨ò? ??¥_ ?i% ? b訥 ? ?? classμ
è¨ ? ??
?? a ü
13? charactor ? ìèè$?|?
2 ?3 numeric L ?_
3? ? integer? ?_
4 ? logical ?_
TRUE=TaFALSE=F
5ˉ ? complexˉ ?a
6 V listS`¥_
7y0 factor�S:"''
a? I?15:\ˉ ?9 ?"
R S?y?μB?1 1:
EverythinginSisanobject;
EveryobjectisShasaclass.
31.dataframe ^ I 1$
6
dataframe
? V[ ?3 ^B? ??¥ ? "b ? V[ ^??] ??¥
?3ay0a3?
?F?¥ ? ? matrix-likeb
32.??¤?f ?¥} ?$
Yèf ?Fo31Rü ?/F31° A¥f ?íú'' Vb1?
dist
?μ H???f ? V? ^B? ?f ? GenericFunction
?¥ZEü31
?éB/5 P
¨methods()f ? ?° A?? ?f ?¥ Vs? 831¥f ?4 ?íú|ù53 %b
1summary#Itisagenericfunciton
methods(summary)#listoftheS3methods
3summary.lm#maybeyouwanttoknowthelinearmodels’ssummary
?T1??ù? V[?/÷} ?a ê .tar.gz1?R-2.5.1.tar.gz
33.áX° AB? ?¥- a+?8 1÷$
V[ P¨head()tail()f ?b
1head(CO2)
? ?f ? ^ ?f ? ? ì V[?¨?_ a ?a ? aVìf ?b?ToX ? A A`
?¥Bt=?? V[ P¨car?¥somef ?b
34.R? T¥?|? ^ I 1il$
&èn¥lmglm? ? ay~model ^B?+?¥ì TV U[y1Y?M ?1modelb
?model?¥M ?+ ? ?¤??: ?V UM W¥\?oT¨"b" +?:á ì P¨
? ?V U0a+b+a:b0b(a+b+c)^2V U(a+b+c)?(a+b+c)''?y íaabac?ò?y í¥
?oT¨b?V U??-ib(a+b+c)^2?a:bV U0a+b+c+b:c+a:c0b TVr?"
M ?y0? ??|9 ^ V[i¥b?0log(y)a+log(x)0 ^?E¥b
?|.updatef ??μ+ y¥il ?V U\Xüi"-ib
1fm fm0 ?H??¥?ì lattice?má ì?? A?j?| ? V[¨ ?S U\HqM "b
35.R ú ? V[ P¨ SD9 ?E 1$
V[b
1e10==10000000000
21.2e?4==0.00012
4S??|¥f ? V[ P¨getAnywhere()f ?¤} ?
7
xC {? {
36.R V[| ed9èq c?¥ ? 1$
V[ P¨foreign ? V[|Minitab,S,SAS,SPSS,Stata,Systat,dBasei¥ ?
37.R V[Excel¥ ? 1$
V[??wi°¤|Excelóq?oμ±è??Excel ú ?μ I 1êbYèμ??ZE
|Excel
1.|Excel 6i1csv(CommaSeparatedValues)óq P¨read.csv()f ?| wi
2.FRODBC P¨odbcConnectExcel()f ?|xlsóq
library(RODBC)
2z dd 4close(z)
W%h? IRDataImport/Export
3.xlsReadWrite?¥read.xlsf ?b
38. V[|R?A U¥2T {?óq 1$
V[b P¨sink()f ?b
data(CO2)
2sink("CO2.txt")
CO2
4sink()#gotoyourworkdirectory,youwillgetCO2.txt
39.???¨R¥ {?$
R4 capture.output()f ???f ? V[|R¥ {??13?óqb
glmout 2glmout[1:5]
???TFX¤??
¥ {GotoLATEX!
40.R V[V=i°¤ ? 1$
V[b J31|¥=? P¨
data 2write.table("clipboard")
8
41.8"|y0(factor)D1 ?3
??ù5 Hμ? 3L !f ^B??"¥y0`á ì V[ P¨
as.numeric(as.character(f))
2#or
as.numeric(levels(f))[as.integer(f)]
42.R V[ P¨è0Vì {? ? 1$
V[ P¨edit()?flx()f ?b
1data edit(x);fix(x)
43.1 I 1?á P¨source() H??A U {2T$
31A U {¥` P¨print()? P¨source(flle,echo=TRUE)b?TR} ? ú ?c
sink()- ?¥f ?A? P¨source(flle,echo=TRUE)??¤???¥ {2T?5sink¥
`|1 bb
44.R V[ { VTEX P¨¥ó'' 1$
V[? IHmisc?¥latex()f ??xtable?¥xtable()f ?b
a 2colnames(a) xtable(a)
xtable()f ? V[¨?á 3HTMLì T¥e ??"R 3?¥Vìü V[dèZLa?
1??
?wordapowerpoint? ?ó3) ?èqb
{LATEXì T¥Vì? V[quantreg?¥latex.table()f ?b
45.s??óq?á?? ?''
R ú ? P¨A? P¨ ?Q|×?|×V Uóq ^?1?
1d:nnR?2.4.1nnlibrarynnxgobinnscriptsnnxgobi.bat
d:/R?2.4.1/library/xgobi/scripts/xgobi.bat
??? V[ P¨flle.choose()f ?u 7B?WindowsSóqê4? m?ê4óqb???
μ V[ P¨choose.dir()u 7WindowsS" cê4? ,b
46.R V[°¤V ? o| ? 1$
V[iO? V[YVSQL? ? oé??TbR??SQL?y¥1"? ? oμ z
¥|??t ? o;μ < ? oOracleaMicrosoftSQLServeraIBMDB2?9cGNU
GeneralPublicLicense(GPL)/??¥MySQL? 7÷ ? ob
9
RMySQL5?4 ?MySQL ? o¥¤ gRODBC4 ÷1<W ? o¤ g¥3
%Z?||? ?μSODBC¤ g¥ ? obYV??Z TM]¥R} ? V[ZL1?¨?
?] ??¥ ? ob
library(RODBC)
2ch stocks 4odbcClose(ch)
ü? kWindowsü ? ¥MicrosoftSQLServeraAccessaOracleaMySQLaPostgreSQL?
Linuxü ? ¥MySQLaOracleaPostgreSQLaSQLite?μ z¥?¨? è W%? IR-datab
xD ? ) ?
47.??÷?? >′$
R? P¨NA notavailableV U? >′1?iR S?y?NA]" ^B? ?′6
x 2x>3
class(x)
#?? ^?M? H?? P¨
1x==NA
??? >′b7 ^ P¨f ?is.na() ?? ^?1? >′ P¨
1x[!is.na(x)]
÷"? >′b
48.??|3?1M1 73?$
? ú¨?eval()?parse()f ?b n5 P¨parse()f ?|3?1?1Vr T expression7a
P¨eval()f ?Vr Tp3b
1x1:10
a"print(x)"
3class(a)
eval(parse(text=a))
49.??_B?_ Fí í$
? Iappend()f ?b
531DBI¥|?
6Rμ?? ?′TRUEaFALSEaNA
10
x1:5
2(foo append(x,0,after=1)
50.??M"?( ) ?
V[ P¨f ?subset(select=)? P¨/S
1x dim(x)
3print(x)
new.x1 5new.x2 new.x1;new.x2
Y L 1?ê|+?Hq/¥ ? ? subsetf ?] P¨/SrTM]
iS 2iris[iS,c(1,3)]
subset(iris,select=c(Sepal.Length,Petal.Length),Species=="setosa")
51.??1? ? ? ^?M]$
1? ??í í ^?M]?T ??í í?M] 1? ? ? 9M]
1a1 a2 3a2[[3,1]]2?>a2[[8,2]]
any(a1!=a2)#all(a1==a2)
any()f ? V[Rí ^′ ^?à μB?1?¥ ?′b7 ? ?¥í íμ?M?¥f ?5
a1!=a2
|Ríà B?TRUE 1any()f ?|?1TRUEb]"9 V[ P¨identical()f ?b
1indentical(a1,a2)
?T31Rí ? ? ?M]¥ê? V[ P¨
1which(a1!=a2,arr.ind=TRUE)
arr.ind?
^arrayindices-iRí ? ¥? ê?b
52.ᥠ? μM]¥??????t?$
? Iuniquef ?buniquef ? V[??_ a ? ? ? ? ¥ ? ?×ˉ¥í íb
11
1x (xu 3unique(x)#ismoreefficient
? úduplicatedf ?Rí í í ^?×ˉ¥ ?′b
53.?? ?
arrayé??MD$
P¨f ?aperm
1x xt 3dim(x);dim(xt)
54.??÷"list?¥í í$
R? P¨NULLV Uír¥`b
1lst lst[["a"]]["b"] 3lst
55.?? ???( )T9 ?$
P¨f ?apply()
1vec=1:20
mat=matrix(vec,ncol=4)
3vec
cumsum(vec)
5mat
apply(mat,2,cumsum)
7apply(mat,1,cumsum)
56.????v ¥R?''
?TF P¨|??5Vr T¥ó''I¥? V[ I n¨?5Vr T(RegularExpression)
?|v ¥} ??B?.Róq?T31??¥?source(.R)-F?#'' V? V[ P
¨
1if(FALSE)f
somethingpassby
3g
57.?? ? (dataframe)¥ T ?DMD$
P¨transform()f ??T 8? I?transform
12
58.??p3 Fü?_ ¥′$
pmax()?pmin()?
1x1:10;y pmax(x,y);pmin(x,y)
59.????5 ?Fé?d9s$
? Itapply()
n17;fac 2table(fac)
tapply(1:n,fac,sum)
4tapply(1:n,fac,mean)
##orreversealist
6to tapply(to,unlist(to),names)
tapply()¥èn?Zμs?ò?FYé?meanavar sd¥9 ?b a?à1d9?¤? a 6
?B?f ?aggregate() ?|tapply()f ?`1_ ¥K? ?Z?
? b7
1attach(warpbreaks)
tapply(breaks,list(wool,tension),mean)
3aggregate(breaks,list(wool,tension),mean)
##fromthehelp
5aggregate(state.x77,
list(Region=state.region,
7Cold=state.x77[,"Frost"]>130),
mean)
60.? ? ¥
^?1 ?3$
sapply(dataframe,is.numeric)
61.BF ?? ?| ? $
f ?sample()
sample(n) ?F?1;:::;n
sample(x) ?F?_ x;length(x)>1
sample(x,replace=T)3?{E
sample(x,n)dbí¥Vx?|n[
sample(x,n,replace=T)bí¥Vx?|n[
sample(x,n,replace=T,prob=p)[à qpbí¥Vx?|n[
7??]"à1d9¥VC? T?B"
13
n1000
2x plot(cumsum(x),type="l",
4main="CumulatedsumsofBernoullivariables")
? V[? I?17:?1?EX?s?¥ ? ? f ??
rnorm(100,mean=0,sd=1)
62.??? μ¥ | ? ? ?i$
á ìüè??? ? ? ?μM]¥ HW4?′??t ??DM]b) ?¥÷Eü ^ P¨
merge(x,y,by.x=,by.y=,all=)f ?b
63.??| ? S?$
? Iscalef ?b
1x m 3n 64.1 I 1flvenum?summary ?f ?Rí¥2T?]$
y1 e ì ? í ? ?Bá ?[μt??|=??]? e ì? Lμ%±μYb
1>fivenum(c(1,4,6,17,50,51,70,100))
[1]1.05.033.560.5100.0
3>quantile(c(1,4,6,17,50,51,70,100))
0%25%50%75%100%
51.005.5033.5055.75100.00
á ì A/ e 쥥?lsê ? ^·μ?s- ¥ ? l?¥ ?′ summary()f ?'' P¨s
ê ?àQá ì V[ A?14;34sê ?¥?l
1+14(length(x)?1);14sê ?
1+34(length(x)?1);34sê ?
7flvenum()f ? ^?? ?¨?ê ?àQb
xE ?D ?
65.??SwLs$
R?y P¨integratef ? ?¤?s2T?
14
1integrate(dnorm,?1.96,1.96)
integrate(dnorm,?Inf,Inf)
3##aslowly?convergentintegral
integrand 5integrate(integrand,lower=0,upper=Inf)
66.??¤?B? _ $
?? V[ P¨f ?t()R?ax1\integer" ?? ? ? H V[¨t(t(x))¤? _
1x1:10;class(x)
t(x);class(t(x))
3t(t(x));class(t(t(x)))
?_ a _ èè?μB?1??^?| ù′¥1Z
1x%?%x
9 ?¥ ^xTx 9 ?xxT P¨%o%outer()f ?bcrossprod()f ??E ???f ?
1XT.y
?°¤9 ?XTY V[ AT-?¥ 6B?VrZ T??crossprod()÷1μr8b??outer()f
?¥ ?il ?è¨????m ? 1?á ì9 ?
10£sin
px2+y2
px2+y2
1?¥Rf ?9 ?1
1f z 67.R??é?ˉ ?9 ?$
? Icomplex()f ?¥úùb
x1+1i#x 2Mod(x);Conj(x)
68.?? 3?? ?$
B?_
P¨diag()f ?¤??Lí í1_ ¥? ?? ?Z P¨Nf ?¤?Z?
¥?ê ?b
69.p ?¥+?′?+?_ ¥f ? ^ I 1$
? Ieigenf ?
8? ??v H?dè üA,
15
70.??/
/?? ?$
? If ?lower.tri()?upper.tri()b
Rmat 2Rmat[lower.tri(Rmat)]0
Rmat
71.p ?Z??? ?$
x^(1/3)bR ú ?sqrt()f ? V[9 ? 7üZ#? m?^w? 7 ?Z9μf ?b Y L R ú ?
P¨^ ?T af ? ?b^?? ^ ??|? V[ AT ^f ?
1"?"(x,1/3)
R?¥ ??| ?
R?¥ ??|
?D ?+,-,,/,^,%%,%/%Fahaea"aeZa? ?a?"
? ?>;<;>=;<=;==;!=v?l?v???l????????
72.??p ?ò?( )¥ (′$
?T ? ? ^?v?? V[ P¨apply()f ?browMeans()?colMeans()f ? V[÷ y1¤?
F1¥2Tb
1m1000;n3000
A 3system.time(B1 system.time(B2 73.??9 ?F? ?¤? ?μF?$
choose()¨?9 ?F? ??nk¢f ?combn() V[¤? ?μí í¥F?b P¨factorial()9 ?¨eb
74.??R ú ?p ê? ?$
P¨f ?D()
f1 2f2 D(f,"x")
75.??pBíZ?¥?$
P¨uniroot()f ??Vuniroot ^?=sE ?9 ?Z??? SuW?? ?@1p H?R
íp?b
1f uniroot(f,c(0,2))
16
?TBíZ?¥? ^′ 1? V[ P¨optimize()f ? ?p′b
f 2optimize(f,c(?2,2))
76.??Eú ? ? ?s? ? $
P¨rnorm(n,mean,sd) ?á 3n? ?1? (′1meanSμ1sd¥ú ? ? ?s?¥ ?
bR ú ?YVs?-9F3‘d’V Uà q áf ?‘p’V U ?s?f ?‘q’V Usê
?f ?‘r’V Uá 3?s?¥ ? ?b?ts? 8 V[? I?20:?\??S áwL"
R-intro?¥Probabilitydistributionsc?
help.search("distribution")
P¨?tf ? V[?^ ?¥é?M1¥s?¥à
q9 ??X?X~N(3;1)9 ?
P(26X65)
?¨? ?s?¥ ?s?f ?pnorm
1pnorm(5,3,1)?pnorm(2,3,1)
9 ?2T10.8185946''·m?|?¥ ?b
?202468
0.0
0.1
0.2
0.3
0.4
Density
P(2 xF3??T
77.Rvl ù? 1$
R?μ??Unix¥#Rvl ^ ù?¥b V[ P¨tolower()atoupper()acasefold()
? ?¥f ?3?é??b
1x"MiXeDcAsE123"
chartr("iXs","why",x)
3chartr("a-cX","D-Fw",x)
tolower(x)
5toupper(x)
78.R?2T {?óq? Hóq? V[¨M }9 ?$
V[YV P¨paste()f ?b
17
1for(varinletters[1:6])f
x 3write.table(x,paste("FOO",var,".txt",sep=""))
g#Youwillget"FOOa.txt"...
79.R??? P¨?5Vr T RegularExpressions
R?μ?? ??¥?5Vr Textendedregularexpressions P¨f ?grep(extended=TRUE)
abasicregularexpressions P¨grep(extended=FALSE)Perl-likeregularexpressions P
¨grep(perl=TRUE)b1?\."¨ ??¥?i3?
P¨\n:" ??¥\."
grep("J.",month.abb)
W% V[? Ihelp("regex")b
80.??3?1?ê|+?ê?¥3?$
? Isubstr()f ?b
1substr("abcdef",2,4)
substring("abcdef",1:6,1:6)
??f ?] H|??ó¨ ò ?) ?\e?"?\??"? ^B??p¥ê4¥b
81.??Rí3?? ?$
? Incharb
nchar(month.name[9])
xG°ù HW
82.°ù V[S ? ? ? 1$
V[bB?á ì31 P¨as.Date()as.POSIXct()f ?||¥°ù 3?1?1\Date" ?
? ? \Date" ?? ? V[é? ? ? ?b
1d1 D1 3D2 D1+2;D1?D2
5difftime(D1,D2,units="days")
83.??|°ùV U1\?ù°,22t2007"??ì T$
P¨format()f ?b
18
1format((Sys.Date(),format="%A,%d%B%Y")
8format? ? V[? Ihelp(strptime)¥details?sb
xH?mM1
84.??]B? ??fm$
? ú4??3 %Z?
????m? ??par(mfrow=c(2,2))par(mfcol=c(2,2))
?÷1<v??¥layoutf ? ? V[ !?m??? ¨??m?vl
?split.screen()f ?b
wi P¨layout()f ?StatisticswithR¥B? è0
1layout(matrix(c(1,1,1,
2,3,4,
32,3,4),nr=3,byrow=T))
hist(rnorm(25),col="VioletRed")
5hist(rnorm(25),col="VioletRed")
hist(rnorm(25),col="VioletRed")
7hist(rnorm(25),col="VioletRed")
85.?? !?m?H?vl
???m? ?par(mar=c(bottom,left,top,right))bottom,left,top,right 1?? ?sY ^
?bottom,left,top,right¥éa ? ^c(5,4,4,2)+0.1b????m? ?par(mai=
c(bottom,left,top,right))[?j1?ê ?·?H?vlb
86.訥pch?|?μ''t$
pch ^plottingcharacter¥ êbpch?|
V[ P¨\0:25" ?V U26?S M ?
A·m\pch?|"b???|9 V[ P¨
#;%;?;j;+;?;:;o;Ob′¤?i¥ ^21:25
?+??| V[pointsf ? P¨?]¥t
?A bg=? ?b
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1op x 3plot(x,sin(x),type="o",bg=par("bg"))
points(x,sin(x),pch=21,cex=1.5,bg="red")
19
87.??Xμm? FBH £üL
P¨? £ü?m 7abline() ? V[T £üL y′h=a<L x′v=?|L ? a=|
qb=b
R?¥?m 7 V[s1\ú £ü" Highlevela\? £ü Lowlevel"?\?o T" Interactive
???m 7b
e11 a\ú £ü"?m 7 V[m? !! ???m\? £ü"?m 7|Xüi
m? @F÷¥?m???aLaH?? P¨\?o T"?m 77y¥?m V[ P¨
? ?S? ?¥?? ? ?@F4|?m?bXμm? @F???1 P¨\? £ü"?m
7b
88.??S áwL$
訥÷E ^Sx¥B?? ?aSdfunction(x)1?
x=seq(?3,3,.05)
2plot(x,dnorm(x),type="l")
lines(x,dt(x,1),col="red")
dfunction(x)?¥function ^·s?B V[? IR-intro?¥Probabilitydistributionsc?
help.search("distribution")b1?/M1s?f ?? I?17:?\??Eú ?s? ? "b
R?¥s?f ?
s?Rf ??F? ?a? ?
betabetashape1(fi),shape2(fl)
=[binomsize(n),prob(p)
′2chisqdf
(unifmin(a),max(b)min=0;max=1
· ?expraterate=1
Ffdf1(r1),df2(r2)
? ?gammashape(fi),scale()scale=1
?+?hyperm=N1;n=N2;k=n
? ?normmean(?),sd()mean=0;sd=1
{ ?poislamda(?)
ttdf
ˉ?:weibullshape(fi),scale()scale=1
89.??Fm è$
??m?a P¨legendf ?help("legend")
1with(iris,plot(Sepal.Length,Sepal.Width,
pch=as.numeric(Species),cex=1.2))
20
3legend(6.1,4.4,c("setosa","versicolor","virginica"),
cex=1.5,pch=1:3)
90.8 1Sfm$
? Ipie()f ?bfmZ U ? ¥? ??μy1á ì¥?é?ê1? ù?71 óu×?
?? $?μbyp P¨H?m barchart??m dotchartb
91.??S?=m$
? Istemf ?b
stem(faithful$eruptions)
92.R??S ?USm$
R? V[YV?m? ?par(new=TRUE) P¤???=??m(hight-levelplot) H =?B?
?mu×?" f?m?×?B A ?ü ^ ?USmb/ ?¥ è0 ^]Bfm ??
GDP? >< q(UR)
1year1995:2005
x1 3x2 par(mar=c(5,4,4,6)+0.1)
5plot(x1,axes=FALSE,type="l")
axis(1,at=year,label=year);axis(2)
7par(new=T,mar=c(10,4,10,6)+0.1)
plot(x2,axes=FALSE,xlab="",ylab="",col="red",type="b")
9mtext("UR(%)",4,3,col="red")
axis(4,col="red",col.axis="red")
??wi P¨ ?USm ?é? ? í ??"??^/?3biOR?Si?m?T1
??^ àμA1?? ?USmb
93.??1?mF??ì$
P¨grid()f ?
plot(1:3)
2grid(NA,5,lwd=2)#gridonlyiny?direction
94.?T?m HS5 té??D?$
V[ P¨strwrapf ???f ? V[|?l
?ì Tb
plot(0,main=paste(strwrap("Thisisareallylongtitlethat
2icannottypeitproperly",width=50),
21
collapse="\n"))
95. V[u 7?m? !! 1$
V[b?u 7?m? !!a P¨dev.list()3 Am? !!¥ ?" "
!!B P¨dev.cur()3
A?- P¨¥m? !!dev.set()?M·?¥m? !!dev.ofi()1>m? !!b
96.USy ¥ ?3?? £üb?$
ˉ? ^?m? ?ù5
1?par#seelas
plot(0,0,xaxt="n",type="n",ylim=c(0,100),las=1)
3mtext("35",side=2,at=35,line=1,las=1)
97.訥?m !!?μ''t$
R|?¥m? !!μ?/+? ? I?Devices
Rm? !!
? í ?
àx11X3 g
A UwindowsWindows3 g
postscriptpsì Tóq
pdfpdfì Tóq
pictexLATEX P¨¥óq
óqpngpngì Tóq
!!jpegjpegì Tóq
bmpbmpì Tóq
xflgXFIG P¨¥m?ì T
win.metaflleaemfì T¥óq
a?Windows/μr
? úwi P¨postscript()f ?y1psm?ì T1 O ?mì TOY¨?? 98.??S ?rm$
R ú ? P¨starsf ? ?S ?rmb
1stars(state.x77[,c(7,4,6,2,5,3)],full=FALSE,
key.loc=c(10,2))
? ú¥¥full=FALSE? ?V Uo?? ?rm¥ ??s Q-???? ?rmkey.loc? ?
V Um è¥ê?b
99.1 I 1R??A U8?[ ¥t?$
??m? ?col P¨ ?3 ?}9t? H?μ??f?? ^y1R=???ea18?t?
22
palette()
2barplot(rnorm(15,10,3),col=1:15)
palette(rainbow(15))
4barplot(rnorm(15,10,3),col=1:15)
palette("default")
R?μ657?t?? V[ P¨ ? ì¥? V[YV
1colors()
?¤?? Y L μtt??}V¥t?×ˉR?t??o?A U502?t?b?? V[ P
¨f ?rgb() ?·??i??b
100.??¨?]¥t? ?}V ? $
ú)?mf ?B??μcol? ? V[ !?b?^barplot()? ?m? V[ P¨\t?F"(color
sets) ? !?t?t?F ??/+ ?
Rt?Ff ?
? í ?
rainbow()???(xbxbxbxbxbxbxb)
heat.colors()£?à??(xbxbxbxbxbxbxb)
terrain.colors() s?a5?àa?(xbxbxbxbxbxbxb)
topo.colors() '' ??à05?(xbxbxbxbxbxbxb)
cm.colors()0 ??a?0,?(xbxbxbxbxbxbxb)
gay()agrey()??(xbxbxbxbxbxbxb)
1x1:10;names(x) barplot(x,col=rev(heat.colors(10)))
3barplot(x,col=gray((1:10)/10));
101.8"|R¥t?]RGB? ?$
? If ?col2rgb()
1write.table(t(col2rgb(rainbow(7))/255),sep=",")
102.???? ??m?¥vl$
Windowsü ?/?èf ?u 7?m3 g??3 gvl???°¤i P¨savePlot()
f ?i??9 V[ Y5¨
1windows(width=,height=)
u 7B??lzvl¥3 g?a?m? V[ P¨pdf(),postscript(),png(),jpeg(),pictex()?
\a ? 3?"f ?
23
1##startaPDFfile
pdf("picture.pdf",height=4,width=6)
3##yourdrawingcommandshere
dev.off()###closethePDFfile
?tf ??μ !?m?vl¥? ?? V[ P¨
dev.copy(device,file="",height,width)
7b
103.??E? μ?$
? μ? V[¨S? ?¥ ?E′¥ ?? ?E
1#twodimensions
n100
3x y 5plot(x,y,type=’l’)
104.??¤ ?¤???¥üáwL$
?TX?S?t?¥f ? V[ P¨curve(expr,from,to,add=T)f ?bQ- P¨ ?ZwLμ
′f ?spline(x,y,n=)?
1x1:5
y 3plot(x,y)
sp 5lines(sp)
105.?ì(lattice)?m??Y?mμ I 1uY$
?ì lattice?m L=
^S-plus?Trellis?mR?¥ LC ^í ? V j?¥ZEb?ì
?mM??Y?m ? a ^B??μ\%?ì T"¥?mZ T?? ?M ? a?4??b?T
? s ??]¥ ?Y31|?t ?Y/¥ ? é?1??ì?m ^??p¥ê4
1library(lattice)
histogram(~heightjvoice.part,data=singer)
訥lattice?mf ?μ
24
è¨lattice?mf ?
f ? a ü
xyplot(y~x) ?M ??m
dotplot(y~x)Cleveland?m(??? ?Fm)
barchart(y~x)yx¥H?m
stripplot(y~x)B?mxA? ^ ?′?y V[ ^y0
bwplot(y~x)QLm
histogram(~x)°Zm
106.??????m$
? Ipersp()contour()f ?b? ú31?i¥???m????US¥? Tb? I?15:?¥
outer()f ?b
107.XüB? ?′¥ ?? 1B?t?Zì¥ ? I 1f ?$
? Iimage()?fllled.contour()f ?
x 2f r 410?sin(r)/r
g
6z image(x,y,z)
8filled.contour(x,y,z)
108.??m???vl]yM ′?1 è???$
R?S? ?m?e?y1R¥??m? ? V[ P¨M
x1:10
2y symbols(x,y,circles=y/2,inches=F,bg=x)
109.áX1B? ? ¥ ?B ?SQ{Qm$
P¨apply()f ?T¨? ?¥? O?E ?R?¥A T?ì
1table par(ask=TRUE)#waitforchanging
3results=apply(table,2,qqnorm)
par(ask=FALSE)
110.??B?°Zm @FB?l¥QLm$
25
°Zm¥ baê?@F 6?¥lm ^m èB"ˉ? P¨? ?par()
x 2hist(x)
op 4boxplot(x)
111.??R¥?m?F? ?D T ?3?$
? I?plotmath ?LATEX¥¨???C=??Edè ? ?b
x1:10;plot(x,type="n")
2text(3,2,expression(paste("Temperature(",degree,"C)in2003")))
text(4,4,expression(bar(x)==sum(frac(x[i],n),i==1,n)))
4text(6,6,expression(hat(beta)==(X^t?X)^f.1g?X^t?y))
text(8,8,expression(z[i]==sqrt(x[i]^2+y[i]^2)))
112.??H?m A U ??bar¥ ?′$
?T üabarplot()f ? L ^??)?m 7rect()f ?/¥/ ?¥ è09ü?4 ?3
1x1:10;names(x) b 3text(b,x,labels=x,pos=3)
113.?????? ?wL$
? f ? T¥''?mb°?US"/ V P¨? ?Z?
(xa)2+(yb)2=1=)x=asin;y=bcos;0<<2…
1t x 3y2?cos(t)#b=2
plot(x,y,type=’l’)
114.word ú?? P¨R 3?¥úé ?m$
O ?m¥rT ^Kz¥1?epsapdf7? ^êm pngajpgatifi?bword ú ? V[ P
¨eps ù?à A U? ^?z?u?rT??pb
xId9?
115.μ àμ°¤9 ???ê¥f ?$
26
??1-B?9n?
t HWbFBasics?4
skewness()
2kurtosis()
V[°¤9 ?ê??b
116.??S?- óV$
table()f ?btable(x)1x¥? ?Vtable(x,y)1?- óVb
x 2prop.table(x,1)
117.??SL?íB?$
L?? ^K??¥ü?d9ZEOà?ˉ?μ<W?¨?C}d9ZE? ^N$ ?
Z ?¥bKe?¥L?íB?1
yi=fi+flxi+?i
?fi1? [fl1?¥| q?1μ[b
lm()f ?4 L?íB¥9 ?ZEb
lm.swiss lm()¥2T ^B?cíB?¥ V ?c[/?
coe–cientsíB" ? ?
residualsRí??μ ?
fltted.values?E?′
......
V[ P¨?/ 7¤? V?:
1names(lm.swiss)
summary()?anova()sYRííB?¥à1??ZμsVb
1summary(lm.swiss)#thesameassummary.lm()
anova(lm.swiss)
4|??¥ ?f ?μ? e V[? IR-intro?StatisticalmodelsinRB?b
?T) ? ? ¥ ?v V[ P¨biglm?¥biglm()f ?b??f ? V[¨?\Z " ?
¥íBEb
118.??÷??$
? Iupdate()f ?
27
summary(f0 2f1 summary(f1)
119.?? P¨??íB$
R ú V[ P¨9 ???íB¥step()f ?b ?[9 ?AIC?d9 15ê|Kl¥AIC
?d9 ?r???íB¥"¥b
1utils::example(lm)
step(lm.D9)
stepf ? V P¨\both,forward,backward"??ZEa1\backward"b??F? V[? I
add1drop1f ?b
120.R??? LCsê ?íB(QuantileRegression)
? Iquantreg?quantregForest
data(engel)
2taus rqs 4for(iinseq(along=taus))f
rqs[[i]] 6tau=taus[i],data=engel)
lines(log10(engel$income),fitted(rqs[[i]]),col=i+1)g
8legend("bottomright",paste("tau=",taus),inset=.04,
col=2:(length(taus)+1),lty=1)
121.??¤?B?? ?98 (′?¥uW9$
?e?t.test()f ?
1x t.test(x)
122.??S ?s$
K (′ ?(kmeans())
x 2matrix(rnorm(100,mean=1,sd=0.3),ncol=2))
cl 4plot(x,col=cl$cluster,pch=3,lwd=1)
points(cl$centers,col=1:2,pch=7,lwd=3)
6segments(x[cl$cluster==1,][,1],x[cl$cluster==1,][,2],
28
cl$centers[1,1],cl$centers[1,2])
8segments(x[cl$cluster==2,][,1],x[cl$cluster==2,][,2],
cl$centers[2,1],cl$centers[2,2],
10col=2)
aQ ?(hclust())
n 2(x hc1 4hc2 hc3 6layout(matrix(c(1,1,2,3),nrow=2,byrow=T))
plot(hc1);plot(hc2);plot(hc3)
?V??á ì V?o31`¥s ?? 1 P¨cutree()f ?9 ^?p¥ê4
1cutree(hc,k=1:3)
???μS ?¥cluster
1library(cluster)
clusplot(x,pam(x,2)$clustering)
123.??S??ss$
stats?¥princompf ?b
(pc.cr 2plot(pc.cr,type="lines"#or"barplot"
)#orscreeplot
4loadings(pc.cr)
princomp()?¥? ?cor=TRUEV U P¨"''M1 ?T??ssQ- P¨"''xZμ
?bloadings()Ríy0?bscreeplot()?? T Fmb
124.8"Sy0s$
R? P¨factanal()f ? ?é?v ??y0sb
example(factanal)
125.??"'' ? é?? ?_$
1?èn¥ZEshapiro.test()ks.test()(Kolmogorov-Smirnov_)jarque.bera.test()(31
tseries)b?? I ê¨T? ?_¥normtestfBasics?¥M1f ?b?+?
?$và4
E+?_f ?b
29
126.??S¥t_$
? It.test()?¥paired? ?b
1require(stats)
##Student’spairedt?test
3t.test(extra~group,data=sleep,paired=TRUE)
? ú31?i¥ ^ ? ¥ c?? T ?1uY?SPSS
Y L ?TF ?d9_¥?F?? V[ P¨
1apropos("test")
?Rí ?μ1?\_"¥?b1?Bt訥_
extragroup
0.71
-0.61
¢¢¢¢¢¢
4.62
3.42
bartlett.testZμ Q?_binom.test=[_
chisq.test′2_cor.testM1?_
flsher.testFisherú?_friedman.testFriedman??_
kruskal.testKruskal-Wallis??_mcnemar.testMcNemar_
pairwise.t.test (′¥×1?PP.testPhillips-Perron_
var.testZμ1_wilcox.testWilcoxon??_
DfZ¨?
127.R??S2Z??$
? Isemb
128.[ TíB?? P¨ I 1f ?$
P¨I() è?
1lm(y~x+I(x^2)+I(x^3))
129.?? P¨Zμs ANOVA$
Zμs]L?íB?? ? ?8è ? ì? ^L??bKe? LCZμs¥f ?1aov()Y
V??f ?= T? T ?·?Zμs ??
Zμs
aov(x~a)?y íZμs
aov(x~a+b) àμ?oT¨¥ ?y íZμs
aov(x~a+b+a:b)μ?oT¨¥ ?y íZμs
aov(x~ab)]
30
130.??p3 àμè ?[¥L?íB?$
o3 T???0'' V
1result 131.??9 ?íB?? ?¥??uW$
? Iconflntf ?glm??nls? V? IMASS?¥conflnt.glm?conflnt.nlsf ?b
1fit confint(fit)
3confint(fit,"wt")
132.logisticíBM1f ? ^$
logisticíB ^1?Y?M 10{1??M ¥<lL?íBù5? ú31 P¨<lL??
glm()f ?O<lL??¥s?B1=[s?b
<lL???¥è¨s?B
s?f ??
ú ? GaussianaE(y)=xTfl?YL??
=[ BinomialE(y)=exp(xTfl)1+exp(xTfl)Logistic??à q?ê probit?
{ ? PoissionE(y)=exp(xTfl) ?L??
a? ? Normal
ú ? ? ?s?B¥<lL?? Y L ]L?? ^M]¥''
1fit1 ]L??
1fit1 ¤?¥2 ? ^Bá¥??r q?μ?b
133.?? P¨??[ TíB$
á ì I níBZ?
yi=fl0+fl1xi+fl2x2i+:::+flkxki;i=1;2;:::;n;
?[ T¥Q ?k1?v Hx;x2;:::;xk?CL?M1ù5b#31 P¨??[ TíB ? X
??Z ?¥??bR? P¨poly()f ?
1(z 134.??p ?0 ?$
? Ihat(),hatvalues()f ?b
135.D-W_'' ú$
31
car?¥durbin.watsonf ?lmtest?¥dwtestf ?b
1help.search("Durbin-Watson")
136.??pSpearman?) kendallM1" ?
cor()f ?a1pPersonM1" ???method? ?'' Vp¤Kendall??Spearman?
M1" ?b
1cor(longley,method="spearman")
?ZE¨o Hq
PearsonL?? ?98L?
Kendall?x]d? ?_
Spearman"''?d? ?_
137.??SDecisionTree$
? ??ZE¥? Tree-basedmodeli?$d9D?¥ù?? ? ?? ? e 5×? H
è$<W?¨b/ ? ^ModernAppliedStatisticsWithS?¥ è031Frpartb
1library(rpart)
set.seed(123)
3cpus.rp plot(cpus.rp,uniform=T)
5text(cpus.rp,digits=3)
138.?? P¨ HW? M1?$
L !?t ^BF (′10Zμ12¥?M1¥?
1á ì?lq¨á?ü (?1
Xt=
qX
0
flj?t?j
p¨1íB?
Xt=
pX
1
fiiXt?i+?t
?lARMA(p;q)V?1
Xt=
pX
1
fiiXt?i+
qX
0
flj?t?j
á ì|F?1?y í¥arma??1arima?R? P¨arima(x;order=c(0;0;0);seasonal=
list(order=c(0;0;0))?é?E?
1require(graphics)
(fit1 3tsdiag(fit1)
32
139.box-coxMD$
MASS?¥
1boxcox()
f ?b
140._sZμ¥Breusch-Pagan_$
lmtest?¥bptest()f ?? ?¨car?¥ncv.test()f ?
141.??S?Ys$
? IMASS?¥lda()f ? FisherLinearDiscriminantAnalysis?qda()f ?b
142.9 ?OLSμ àμeLZE?
μ V[ P¨f ?qr.solve()
1qr.solve(X,y)
?N?(X0X)?1X0y
143.??é???M1s$
??M1s ^¨?ù? F ?M -W¥M1?¥B?d9ZEbR4 cancor()f ?é
?M19 ?b
1pop oec 3cancor(pop,oec)
144.?? P¨RS 3is$
31Fsurvivalb
1#fitaKaplan?Meierandplotit
fit 3plot(fit)
#lifetable
5cbind(fit$time,fit$n.risk,fit$n.event,fit$surv)
?isurvfltf ??sZEtype?μ\kaplan-meier",\eming-harrington",\fh2"??ZE V[ê
4b
xJ e
145.R V[ P¨?: ?A U2T 1$
33
V[bRpad4?]R¥?:¤ gL !Xü?
Rpad V[''1° ARpad¥r
T
1library(Rpad)
Rpad()#enjoyit
146.Rμ ? ??SPSS¥? ? 1$
μ? RcmdrFa P¨ 7
Commander()
? V P¨¥m? P¨? ?b????m? P¨? ?31??$?¥ ef ?#?31
caraefiectsaabindalmtestamultcomparelimpaRODBCargl¥|?b
147.8" ?9 ?f ?? P¨ HW$
P¨system.time()bproc.time() V[¤Ré?i¥ HWsystem.time()YV?¨ Qproc.time()
?9 ?f ??¥ HWb
148.R???) ?1m ? $
R4 maps?mapdata ? ???1m?mapdata4 ?S1m¥M1?
1library(mapdata)
map("china")
?V V??ZE¤?¥?S1m àμ×i¥??u?Oò 8¥?? ^¨ ?3ó 7??
?¨map?¥f ?^
map("state")
B"é?éB?Fyb
?V?TF ?1 ? ? 1maptools| ^B??p¥ê4b ò V[|a) ? bW
`O4 ]PBSmapping,spatstat,maps,RArcInfo,Statatmap,WinBUGS,Mondrian? ?
¥ ¤ gb
149.Sweave ^¨ ?S I 1¥$
Sweave4 B?1\?TEXó''?SI ?" 3?ó?¥?b??¥Sweaveó??;c
TEXó''?cSI ?YVIrK???¥ó?c
?TEXó?¥Ir {
?SI ??
?SI ?¥} ? { ó''am?b
?TX 3÷h? ISweaveUserManual? I? cASweave¥ L èb
?¥ó???V?
34
Sweaveó?Sweave(inR)????????!TEXó?LATEX??????!
dvipdfmx
K?pdfó?
150.?? dbR?a]¨¥=i$
P¨f ?
1gc()
y1R ^=i? ? ?[?R? 81?v¥ ? a'' P÷" M1`=i bW
ˉ?? dbbgc()f ? ù??1¨ ?á=i P¨f ?? ^B?×1¥¨oL ^ db=ib
151.¨ I 1ó''I1?z$
1?訥 ^Tinn{RRWinEdt9ESS(EmacsSpeaksStatistics) .à?iB {I?
UltraEdit10?t?|?R?E¥ú
A Ub?T ^Windows ?ìa/¥¨??t? ^?
3: Y''9? >1B?ê4b
9/a? WinEdtaR?? RWinEdt'' V P¨
1031/a??wordflle
35
? cASweave è
\documentclass[CJK]{cctart}
\usepackage{verbatim}
\title{Sweave L è}
\author{}
\date{}
\SweaveOpts{echo=FALSE}
\begin{document}
\maketitle
P¨Sweave V[??^1|\LaTeX{}]R¥} ??ó??1 V
Ir¥\LaTeX{}ó?b
???¥ó? ú''2ˉ? ^\LaTeX{}? T¥·B¥uY ^
R} ?31b?[$<<>>=$1 7h$@$12á¥
? ú ?b 7h?s
μ ?訥? ?echo?fig, P¨ ?′sYV U ^?|R} ? {?
T1\LaTeX{}ó'' { ^?\LaTeX{}ó????m?b
?éó?o31R?IrBR'' V??\LaTeX{}31¥ { óqb
/ ? ^B?¥t_¥B? è0
<>=
require(stats)
##Student’spairedt-test
m<-t.test(extra?group,data=sleep,paired=TRUE)
print(m)
@
R9 ?V?? 3?¥¥?W2T??^???Só?
1?\texttt{sleep} ? ¥ ?"''¥¥t_2T
?¥$p$-value ^\Sexpr{format.pval(m$p.value)}
? ^°¤ ?
<>=
choose(49,6)
@
?Sˉ ?o ? ???? ??o¥ ? ?F? ???\Sexpr{choose(49,6)}b
YV??ZE) ?‘‘μv 9 ?’’¥ó?1word??ZL b
36
R} ?? V[ ?i? d??t? da??$ {b?T1p {? d
5C? àμ÷z¥3 %÷Eb
P¨Sweave? V[|R 3?¥m?F??\LaTeX{}ó??7?A Y5
S\LaTeX{}31¥m?óq\footnote{Sweave?1? 3?ps?pdfm?}b
/m ^? Titanic|Z4?|?¥ü6 ?a?YaM -? ^?i 1
?M ??¥ ?× Xm
<>=
require(graphics)
mosaicplot(Titanic,main="SurvivalontheTitanic")
@
\end{document}
Copyrightc2008RandalltheContributorstoRFAQ.Allrightsreserved.
R[#RFAQ¥T??μ??c2008b = ?μ? ?b
Permissionisgrantedtocopy,distributeand/ormodifythisdocumentunderthetermsoftheGNUFree
DocumentationLicense,Version1.2oranylaterversionpublishedbytheFreeSoftwareFoundation;withthe
InvariantSectionsbeingContributors,noFront-CoverTexts,andnoBack-CoverTexts.
F V[ Ja??????zó??A?N o1?èqF???¥GNU1?ó?? V£1.2?[a?''
¥H {bInvariantSections ?Contributors àμFront-CoverTexts?Back-CoverTextsb
37
ì?
Symbols
nn............................9
..............................18
.packages.....................6
/.............................9
%%........................15
^.........................16,30
fg...........................12
A
abline.......................20
aggregate....................13
any..........................11
aov..........................30
aperm.......................12
append......................10
apply.................12,16,25
as.Date......................18
as.numeric...................20
as.POSIXct..................18
axes.........................21
axis..........................21
B
barplot......................23
boxcox.......................33
bptest.......................33
Breusch-Pagan...............33
C
cancor.......................33
capture.output................8
car........................7,33
casefold......................17
choose.......................16
citation.......................3
clipboard.....................8
cluster.......................29
cm.colors....................23
col...........................23
col2rgb......................23
colMeans....................16
colors........................23
combn.......................16
Commander.................34
complex.....................15
conflnt.......................31
conflnt.glm..................31
conflnt.nls...................31
contour......................25
crossprod....................15
cumsum..................12,24
curve........................24
cutree.......................29
D
D............................16
data..........................6
dataframe................6,12
demo.........................3
detach........................5
dev.copy.....................24
dev.cur......................22
dev.list......................22
dev.ofi.......................22
dev.set......................22
Devices......................22
diag.........................15
difitime......................18
duplicated...................12
durbin.watson...............32
dwtest.......................32
E
edit...........................9
eigen........................15
ESS.........................35
eval..........................10
F
factanal......................29
factorial.....................16
FALSE......................12
flle.choose.....................9
fllled.contour................25
flvnum.......................14
flx............................9
format.......................18
G
gc...........................35
getAnywhere..................7
getwd.........................5
glm..........................31
gray.........................23
grep.........................18
grey.........................23
grid.........................21
H
hat,hatvalues................31
hclust.......................29
head..........................7
heat.colors...................23
help..........................3
help.search....................3
I
I.............................30
identical.....................11
if............................12
image........................25
integer.......................15
38
integrate.....................14
iris..........................20
is.na.........................10
is.numeric...................13
J
jarque.bera.test..............29
jpeg.........................23
K
kmeans......................28
ks.test.......................29
L
latex..........................9
latex.table....................9
layout.......................19
lda..........................33
legend.......................20
letters.......................23
Library.......................5
library........................5
lines.........................24
list...........................4
lm...........................31
lmtest.......................33
loadings.....................29
lower.tri.....................16
ls.............................4
M
mai..........................19
mar.........................19
matrix...................12,16
memory.limit.................4
merge.......................14
methods......................7
N
nchar........................18
ncv.test......................33
NULL.......................12
O
optimize.....................17
options.......................4
outer........................15
P
Package.......................5
par...............19,21,25,26
parplot......................26
parse........................10
paste......................4,17
pch..........................20
pdf..........................23
persp........................25
pictex.......................23
pie..........................21
plotmath....................26
pmax........................13
pmin........................13
png..........................23
points.......................19
poly.........................31
postscript....................23
princomp....................29
print..........................9
proc.time....................34
prompt.......................4
Q
qda..........................33
qqnorm......................25
qr.solve......................33
QuantileRegression..........28
R
rainbow.....................23
Rcmdr.......................34
read.table.....................8
read.xls.......................8
rect..........................26
RegularExpressions......12,18
rev..........................13
rgb..........................23
rm............................4
RMySQL....................10
rnorm................17,21,24
RODBC.....................10
rowMeans...................16
Rpad........................34
rpart........................32
RSiteSearch...................3
RWinEdt....................35
S
sample.......................13
save..........................5
save.image....................5
savePlot.....................23
scale.........................14
screeplot.....................29
search........................6
sem..........................30
setwd.........................5
shapiro.test..................29
shell.exec.....................4
show.error.messages..........4
sink........................8,9
some..........................7
sort..........................21
source........................9
spline........................24
split.screen..................19
sqrt..........................16
stars.........................22
stats.........................29
stem.........................21
39
step.........................28
strwrap......................21
subset.......................11
substr.......................18
summary....................14
survflt.......................33
Sweave......................34
system........................4
system.time..............16,34
T
t.............................15
t.test........................28
table........................27
tail...........................7
tapply.......................13
terrain.colors................23
Tinn-R......................35
tolower......................17
topo.colors...................23
toupper......................17
transform....................12
tseries.......................29
U
unique.......................11
uniroot......................16
update.......................27
update.packages..............5
upper.tri.....................16
W
windows.....................23
with.........................20
X
xlsReadWrite.................8
xtable........................9
40
|
|