R命令参考卡片中文版
,
, .
R ‘x’
; ; as.is=TRUE header=TRUE factors;
sort(x) x ; :rev(sort(x)) cut(x,breaks) x ( ); breaks . match(x, y) x y , NA which(x == a) TRUE , x choose(n, k) =n!/[(n − k)!k!] sign(x) 0, 1 , -1 , 0 na.omit(x) NA , x , na.fail(x) x NA unique(x) x , duplicated(x) x table(x) x ( subset(x, ...) x ... select x , : x$V1 < 10
expand.grid() rbind(...) cbind(...) .
,
,
x[n] x[-n] x[1:n] x[-(1:n)] x[c(1,4,2)] x["name"] x[x > 3] x[x > 3 & x < 5] x[x %in% c("a","and","the")] x[n] x[[n]] x[["name"]] x$name x[i,j] x[i,] x[,j] x[,c(1,3)] x["name",] ( x[["name"]] x$name n n "name" . (i,j) i j 1
;
I /O file . . file="" . (Connections) (file), (pipes), (zipped files) R windows clipboard . Excel Excel , x <- read.delim("clipboard") Excel , write.table(x,"clipboard",sep="\t",s=NA) clipboard , Excel , RODBC, DBI,RMySQL, RPgSQL, and ROracle . XML, hdf5, netCDF . c(...) ; recቤተ መጻሕፍቲ ባይዱrsive=TRUE
3 "name" ) "name" .
as.array(x), as.data.frame(x), as.numeric(x), as.logical(x), plex(x), as.character(x), , ; : methods(as) is.na(x), is.null(x), is.array(x), is.data.frame(x), is.numeric(x), plex(x), is.character(x), ... ; , methods(is) length(x) x dim(x) ; dim(x) <- c(3,2) dimnames(x) nrow(x) NROW(x) dim(x)[1] ncol(x) NCOL(x) dim(x)[2] class(x) x ;class(x) <- "myclass" unclass(x) x names(x) (names) unname(x) R (names) (dimnames) unlist(x) x attr(x,which) x which attributes(obj) obj which.max(x) which.min(x) rev(x) x rle(x) x x Runs
n n n n+1 "name" 3 (3,5) x
(
)
”topic”
help.start() HTML demo() R example(f) str(a) R (*str*ucture) summary(a) a , a . ls() “ ” ; ls.str() str() dir() list.files() getwd() setwd() methods(a) a “S3 methods” methods(class=class(a)) options(...) ; error install.packages(pkg) pkg update.packages() library(pkg) pkg require(x) library(help=pkg) pkg attach(x) x R ;x save R data file. search() detach(x) attach . assign(x,value) value x, ”< −” quit() R (q() Ctrl z) data(x) edit() fix(x) ‘fix’ ‘edit’ data.entry(x) scan(x) read.table(file) sep="" ;
: width, digits, . from:to ; “:” ; 1:4 + 1 “2,3,4,5” seq(from,to) by= ; length= seq(along=x) 1, 2, ..., length(along); rep(x,times) x times ; each= x ;rep(c(1,2,3),2) 1 2 3 1 2 3; rep(c(1,2,3),each=2) 112233 data.frame(...) , ; data.frame(v=1:4,ch=c("a","B","c","d"),n=10); list(...) , list(a=c(1,2),b="hi",c=3i); array(x,dim=) x ; ; x , x matrix(x,nrow=,ncol=) ; factor(x,levels=) x gl(n,k,length=n*k,labels=1:n) ( ); k ;n ; dim=c(3,4,2)
expression(expr) ‘ ’(expression) is.expression(x), as.expression(x, ...) parse(file = "", n = NULL) , (expression) eval(expr) R (expression)
.
).
(NA).
paste(...) ; sep= ( ); collapse= “collapsed” substr(x,start,stop) ; , substr(x, start, stop) <- value strsplit(x,split) split x grep(pattern,x) pattern ; ?regex gsub(pattern,replacement,x) , sub() , tolower(x) toupper(x) casefold(x, upper = TRUE) x (TRUE) (FALSE) chartr(old, new, x) x old new match(x,table) table x . x %in% table . pmatch(x,table) table x nchar(x) . POSIXct . ( .>), seq() difftime() . Date + ?DateTimeClasses . chron . as.Date(s) as.POSIXct(s) ; format(dt) . “2006-07-24”. . : Date %a, %A “ ”(weekday) %b, %B %d (01–31). %H (00–23). %I (01–12). %j (001–366). %m (01–12). %M (00–59). %p AM/PM . %S (00–61). %U (00–53); %w (0–6, 0). %W (00–53); %y (00–99). . %Y . %z ( .) ; -0800 %Z ( .) ( ). weekdays(x) months(x) quarters(x) . x x x (Q1 - Q4) , “ ”
.
comment.char="" "#" ; skip=n n ; ,NA , 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 , save(file,...) save.image(file) load() save dump("x","...") x “...” cat(..., file="", sep=" ") ; sep print(a, ...) a format(x,...) , R write.table(x,file="",s= T ,s= T , sep="") x , ; quote TRUE, (") ; sep ; eol ; na ; s=NA sink(file) file, sink()
R
( com , , sunbjt@. 1.3 2008-8-3 ) Tom Short tshort@eprisolutions. . ( Tom Short ) . ,
R help(topic) topic ?topic help.search("topic") apropos("topic")