a = c(1,2,3)
help(mean)
?mean
example(mean)
help.start()
help(package="plyr")
help(baseball) 查看plyr包下面的baseball数据集的描述
getwd()
setwd(“c:/myproject”)
ls()
rm(list=ls())
dir()
dir.create(“c:/myproject”)
options()
options(digits=3)
data()
save.image("mylife")
load("mylife")
source("inputFile.R")
sink("outFile",append=TRUE,split=TRUE)
pdf("outPic.pdf")
jpeg("outPic.jpg")
postscript("filename.ps")
mydata = edit(mydata)
fix(mydata)
mydataframe = read.table(file,header=TRUE,sep="delimiter",row.names="name",stringsAsFactors=FALSE)
sink("myout.txt",split=TRUE)
pdf("myout.pdf")
source("s1.R")
sink()
dev.off()
length
dim
str
class
mode
names
c(obj1,obj2)
cbind(obj1,obj2)
rbind(obj1,obj2)
head
tail
ls()
rm(obj1,obj2)
R CMD BATCH options infile outfile
"c:\program\r\r.exe" CMD BATCH --vanilla --slave "c:\myscript.R"
mode(a)
class(a)
is.numeric(a)
is.character(a)
1 == 1
1 != 2
TRUE & TRUE
TRUE | FALSE
! TRUE
patient$gender = factor(patient$gender,levels=c(1,2),labels=c("male","female"))
data
library(MASS)
data(Insurance)
str(Insurance)
names(Insurance)
summary(Insurance)
sub1 = sample(nrow(Insurance),10,replace=TRUE)
Insurance[sub1,]
index = sample(2,nrow(Insurance),replace=TRUE,prob=c(0.8,0.2))
Insurance[index==1,]
Insurance[index==2,]
dose <- c(20, 30, 40, 45, 60)
drugA <- c(16, 20, 27, 40, 60)
drugB <- c(15, 18, 25, 31, 40)
opar <- par(no.readonly = TRUE)
par(mfrow=c(1,2))
par(pin=c(2,3))
par(lwd=2, cex=1.5)
par(cex.axis=0.75, font.axis=3)
plot(dose, drugA, type=”b”, pch=19, lty=2, col=”red”)
plot(dose, drugB, type=”b”, pch=23, lty=6, col=”blue”, bg=”green”)
par(opar)
par(mfrow=c(1,1))
sum.of.squares <- function(x,y) {
x^2 + y^2
}
sum.of.squares(3, 4)
参考资料
- 王路情博客—数据科学家
- 《R in action》