R in action 笔记

##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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值