for:
for(i in 1:10)
print('hello')
i<-10
while (i>0) {print('hello');i<-i-1}
ifelse (score>0.5,print('passed'),print('Failed)
options(digits=3)
attach(mtcars)
aggdata<-aggregate(mtcars,by=list(cyl,gear),Fun=mean,na.rm=TRUE)
#基本条形图
barplot(counts,main='main',ylab='y',xlab='x')
#拼图求均值
states<-data.frame(state.region,state.x77)
means<-aggregate(states$Illiter,by=list(state.region),FUN=mean)
counts<-table(data$T1)
饼图
par(mfrow=c(2,2))
slices<-c(10,12,4,16,8)
lbls<-c('A','B','C','D','E')
pie(slices,labels=lbls,main='ttt')
pct<-round(slices/sum(slices)*100)
lbls2<-paste(lbls,'',pct,'%',sep='')
pie(slices,labels=lsls,col=rainbow(lengtn(lbls2)),main='tt')
#rainbow(length(lbls2)) 代表提供了lsls2长度的不同颜色
直方图
par(mfrow=c(2,2))
hist(mtcars$mpg)
hist(mtcars$mpg,breaks=12,col='red',xlab='mile',main='tt')
#按等分划分
hist(mtcars$mpg,freq=FALSE,breaks=12,col='red',
xlab='mile',main='t',rug(jitter(mtcars$mpg)),lines(density(mtcars$mpg),col='blue,lwd=2)
#添加轴虚线
核密度图、箱线图
par(mfrow=c(2,1))
d<-density(mtcars$mpg)
boxplot(mtcars$mpg,main='tt',ylab='dd')
boxplot(mpg~cyl,data=mtcars,main='tt',xlab='cyl',ylab='mpg')
#分类箱线图