R ëëëkkk¡¡¡
=©©Ðd Tom Short tshort@eprisolutions.
com >, 3www.Rpad.org þ±#©.
¥©©(®¼ÈuÙN) (þÓ
aq,ÛÜV\eZ·-.
Y?¾±9od 4g) KI,Xk1µ½ïÆ
éX: sunbjt@hotmail.com, bjt@ruc.edu.cn
¥©µ 1.2 2007-6-6
ÏÏÏÚÚÚÄÄÄ:::
Ü©R ¼êÑk3©"
help(topic) 'utopic©.
?topic Óþ
help.search("topic") |¢ÏXÚ
apropos("topic") £¤k3|¢´»e÷vKLª”topic”
¤k鶡
help.start() HTML/ªÏ
demo R õUü«
example(f) $13Ï¥~f
str(a) w«R éS3á5(*str*ucture)½{`²é
summary(a) ÑaV, Ï~´5ÚOV;§éØÓá
5a kØÓöª.
ls() w«|¢´»eé; ½pat="pat",Uª^|¢
ls.str() str() |¢´»ezCþ
dir() w«c8¹e©
list.files() Óþ
getwd() ¼ó´»&E
setwd() ó´»&E
methods(a) w«a“S3 methods”
methods(class=class(a)) L¤k±)ûáuéa{
options(...) ½uÛëê; ~^ëêk: width, digits,
error
library(x) \1÷(package); library(help=x) w«÷x ¼ê
Údatasets .
require(x) Óþ
attach(x) òxR|¢´»; x ±¦L,êâµ,½ö´
dsaveMïR data file. ¦^search()5w«|¢´».
detach(x) attach_L§.
assign(x,value) òvalueDx,=”< −”
quit() òÑc R ¬{(q()½Ctrl z)
ÑÑÑ\\\ÑÑÑÑÑÑ
load() \1dsave·-ê|
data(x) \1½ê|
edit() N^©?6ì?U R é
fix(x) ‘fix’ N^‘edit’ ?U‘x’
data.entry(x) >fêâL/ª¹\?6ì
scan(x) l½©¥Öêâþ½L
read.table(file) Ö L ª © ¿ ò Ù M ï ¤ ê â µ;%
@ © Îsep="" ? ¿ x;¦ ^header=TRUE Ö 1 1
I K;¦ ^as.is=TRUE i Î þ C factors;¦
^comment.char="""#")º5º; ¦^skip=n 3Öê
âcaLn 1;[Ï'u1·¶,NA ?n,ÚÙ¦
read.csv("filename",header=TRUE) Ó þ, % @ Ö
csv ©(Comma Separated values)
read.delim("filename",header=TRUE) Ó þ,% @ Ö
tab ©©
read.fwf(file,widths,header=F,sep="\t",as.is=FALSE)
±f ixed width f ormatted/ªÖêâêâµ; widths ´ê
þ, ^uN°Ýiã
save(file,...) ±Ø©²?½é
save.image(file) ¤ké
dump("x","...") òé x 3”...”p
cat(..., file="", sep=" ") r=ziÎ<arguments;
sep argumentsm©iÎ
print(a, ...) w« arguments; ,§éuØÓé±k
ØÓLª.
format(x,...) ªz,Ðw« R é
write.table(x,file="",row.names= T ,col.names= T ,
sep="") 3rx=zêâµ,©; XJquote TRUE,
iÎ ÚÏfÒ¬(")¤; sep ´iã©Î; eol 1
©Î; na "iÎG; ¦^col.names=NA O\IK±
BuÚLÑ\
sink(file) ÑÑ©file, Ñ\·-sink()
Ü© I/O ¼êÑk file ëþ.§²~^iÎG5·¶©½
ë. file="" ¿XIOÑ\½ÑÑ. ë(Connections)±º©
(file),+(pipes),Ø©(zipped files)½ R Cþ.
3 windows ö¸e.©¦^±ÏLi(clipboard)
ª.Ö Excel L,±ò Excel ¥êâi,¦^
x <- read.delim("clipboard")ªÖêâ.XJòêâ\
iø Excel ¦^,±¦^
write.table(x,"clipboard",sep="\t",col.names=NA)
ê⥡pA ^,RODBC, DBI,RMySQL, RPgSQL, and ROracle÷
. ÖÙ¦©ªëXML, hdf5, netCDF ÷.
êêêâââMMMïïï
c(...) ~òXëþ=zþ¼ ê; ÏLrecursive=TRUE
üSüL¿|ܤkþ.
from:to )S; “:” kp?O`k?; 1:4 + 1 “2,3,4,5”
seq(from,to) )Sby= ½må; length= ½¦Ý
seq(along=x) )1, 2, ..., length(along); ~^3Ìþ
rep(x,times) Ex timesg; ¦^each= 5½x Egê;
rep(c(1,2,3),2) ò1 2 3 1 2 3; rep(c(1,2,3),each=2) ò
1 1 2 2 3 3
data.frame(...) M ï ê â µ,C þ U · ¶ ½ · ¶;
data.frame(v=1:4,ch=c("a","B","c","d"),n=10); é á
þ¬W¿þÝ
list(...) MïdCþ|¤L,CþU·¶½·¶;
list(a=c(1,2),b="hi",c=3i);
array(x,dim=) )dx|¤ê|;¦^aqdim=c(3,4,2)½
ê; XJxØÝ,KxgÄÌ
matrix(x,nrow=,ncol=) Ý;Óþ
factor(x,levels=) rþx ?è¤Ïf.
gl(n,k,length=n
*
k,labels=1:n) Ï L ½ Y ² ª ) Y
²(Ïf); k Y²ê; n Egê
expand.grid() Jøþ½Ïf¤k|ܤêâµ
rbind(...) r±1/ª|ÜÝ,êâµ,½Ù¦
cbind(...) Óþ.±/ª
êêêâââ©©©ÚÚÚÀÀÀ
þ¢Ú
x[n] 1n
x[-n] Ø1nx
x[1:n] cn
x[-(1:n)] 1n+1
x[c(1,4,2)] ½
x["name"] ¶"name"
x[x > 3] ¤ku3
x[x > 3 & x < 5] «m(3,5)
x[x %in% c("a","and","the")] ½|¥
L¢Ú
x[n] Lw«n
x[[n]] L1n
x[["name"]] ¶"name"
x$name Óþ.
Ý¢Ú
x[i,j] eI(i,j)
x[i,] 1i1
x[,j] 1j
x[,c(1,3)] 11Ú3
x["name",] ¶"name"1
êâµ¢Ú(Ý¢Ú\eã)
x[["name"]] ¶"name"
x$name Óþ.
CCCþþþCCC
as.array(x), as.data.frame(x), as.numeric(x),
as.logical(x), as.complex(x), as.character(x), ,
=Cþa.; ¦^Xe·-ÜL, methods(as)
CCCþþþ&&&EEE
is.na(x), is.null(x), is.array(x), is.data.frame(x),
is.numeric(x), is.complex(x), is.character(x), ...
uCþa.; ¦^Xe·-ÜL, methods(is)
length(x) x ¥ê
dim(x) #½éê; dim(x) <- c(3,2)
dimnames(x) #½é¶¡
nrow(x) 1ê; NROW(x) ^Ó,´§rþwü1
Ý
ncol(x) ÚNCOL(x) Óþ.
class(x) ½xa;class(x) <- "myclass"
unclass(x) íØxa
names(x) w½é¶¡(names)
unname(x) íØ R 鶡(names)½¶¡(dimnames)
unlist(x) òL x =zþ
attr(x,which) ½xá5a. which
attributes(obj) ½obj á5L
êêêâââÀÀÀJJJÚÚÚööö
which.max(x) £x¥¢Ú
which.min(x) £x¥¢Ú
rev(x) 6x ¥¤k
rle(x) £i§(Runs)&E
sort(x) ,Süx¥;üSü¦^:rev(sort(x))
cut(x,breaks) òx ©¤Aã(½Ïf); breaks©ãê½
©:þ.