资源描述:
《r软件基础知识与实战》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、R软件基础知识与实战第一课:基本知识第二课:基本运算第三课:画图第四课:数据整理和数据分析第五课:统计分析第六课:分布的产生第七课:求导和极值的计算第八课:Bootstrap方法第九课:MCMC算法第一课基本知识一.R的历史与特点Object-oriented语言二.R系统介绍安装镜像Installingpackageslibrary(survival)#加载程序包library(help=survival)#显示程序包survival里的内容help(mean)#查看关于函数mean的帮助search()#给出系统里已加载的程序包searchpaths()#给出系统
2、里已加载的程序包的路径Commandsareseparatedeitherbysemicolonoranewline三.Dataobjects#Thereare7basictypesofdataobjects:#Vector,Matrix,Array,List,Factor,Timeseries,Dataframe#creatingvectors#vectortype:character,numeric,integer,logical,complexmy1<-c(1.2,2.3,3.5,4.6,5.7)my2<-c("Monday","Tuesday","Wednes
3、day","Thursday","Friday","Saturday","Sunday")rep(NA,5)rep(c(T,T,F),2)rep(c("yes","no"),c(4,2))1:51.2:41:-1seq(-pi,pi,.5)seq(-pi,pi,length=10)seq(1,by=.05,length=10)a1=vector("logical",3)a2=numeric(4);a3=complex(5);a4=character(6)#what’sthedifferencebetween?mat1<-rep(1:4,rep(3,4))mat2<-r
4、ep(1:4,3)scan()scan(what="")#扫描字符型变量numbered.letters<-lettersnames(numbered.letters)<-paste(“obs”,1:26,sep=””)#generatingmatrixmat1<-matrix(1:12,ncol=3,byrow=T)dimnames(mat1)=list(c("row1","row2","row3","row4"),c("col1","col2","col3"))mat2<-matrix(1:12,ncol=4,dimnames=list(NULL,paste("c
5、ol",1:4)))mat<-rep(1:4,rep(3,4))dim(mat)<-c(3,4)dimnames(mat)<-list(paste("row",letters[1:3]),paste("col",LETTERS[1:4]))rbind(c(200688,24,33),c(201083,27,115))dim(mat)#arrayarray(c(1:8,11:18,111:118),dim=c(2,4,3))#listattributes(iris)grp<-c(rep(1,11),rep(2,10))thw<-c(450,760,325,495,285
6、,450,460,375,310,245,350,340,300,310,270,300,360,405,290)heart.list<-list(group=grp,thw=thw,descrip="heartdata")names(heart.list)names(heart.list)<-c("group","totalheartweight","descrip")#factorsclasslist<-c("male","female","male","male","male","female","female","male","female")classlis
7、t=factor(classlist)factor(c("Hi","Lo","Med","Hi","Hi","Lo"),levels=c("Lo","Hi"),labels=c("LowDose","HighDose"))cut(state.x77[,"Murder"],breaks=c(0,8,16))cut(state.x77[,"Murder"],breaks=2)cut(state.x77[,"Murder"],c(0,8,16),labels=c("Low","High"))#dataframescars=read.table("D:/93