##1
savehistory('delete')
loadhistory('myfile')
save.image('myfile')
save(objectlist,file = 'myfile')
load('myfile')
dir.create()
##2
cells <- c(1,26,24,68)
rnames <- c("R1", "R2")
cnames <- c("C1", "C2")
mymatrix <- matrix(cells, nrow=2, ncol=2, byrow=TRUE,
dimnames=list(rnames, cnames))
mymatrix <- matrix(cells, nrow=2, ncol=2, byrow=FALSE,
dimnames=list(rnames, cnames))
z <- array(1:24, c(2,3,4), dimnames=list(dim1, dim2, dim3))
str()
summary()
class()
dim()
range()
mydata<-data.frame(age=numeric(0),gender=character(0),weight=numeric(0))
mydata<-edit(mydata)#等价于:
fix(data)
attach()
detach()
with(mtcars,{
stats<-summary(mtcars)
wai<<-summary(mtcars)
})
grades <- read.table("studentgrades.csv", header=TRUE,
row.names="StudentID", sep=",",
colClasses=c("character", "character", "character",
"numeric", "numeric", "numeric"))
status<-c('poor','improved','excellent','poor')
status<-factor(status,order=T,levels = c('poor','improved','excellent'))
sex<-factor(sex,levels = c(1,2),labels = c('male','female'))
mydatatxt <- "
age gender weight
25 m 166
30 f 115
18 f 120
"
mydata <- read.table(header=TRUE, text=mydatatxt)
read.table()#的一些选项:
header
sep
row.names()
colnames()
na.strings#na.strings('-9','?')
colClasses()
skip
stringsAsFactor
text
gzfile()
unz()
##3
abline(lm(mpg~wt))#加了一条最优拟合曲线
pdf('xx.pdf')
plot()
dev.off()
par(no.readonly = T)
par(lty=2,pch=17)
pch#符号
cex#文本大小缩放倍数
lty#线条类型
lwd#线宽
col
col.axis#坐标轴刻度
col.lab
col.main
col.sub
fg
bg
font#字体族
pin#以英寸表示的图形尺寸
mar#边界大小c(5,4,4,2)下左上右
mycolors<-rainbow(n)
pie(rep(1,10),labels = mycolors,col=mycolors)
axis()#坐标轴选项
axis(2, at=x, labels=x, col.axis="red", las=2)
#1234分别表示下左上右,画坐标轴的方位
x <- c(1:10)
y <- x
z <- 10/x
opar <- par(no.readonly=TRUE)
par(mar=c(5, 4, 4, 8) + 0.1)
plot(x, y, type="b",
pch=21, col="red",
yaxt="n", lty=3, ann=FALSE)
#ann=FA
R in action 笔记
最新推荐文章于 2023-06-26 17:27:13 发布