R程式流程控制.ppt

  1. 1、本文档共38页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
R程式流程控制.ppt

範例9:水平和垂直合併 #vertical merge input=read.table(D:\\stella\\R\\input1.txt,header=T) input1=read.table(D:\\stella\\R\\input2.txt,header=T) vall=rbind(input,input1) vall 範例9:水平和垂直合併 #horizontal merge test=read.table(D:\\stella\\R\\input3.txt, header=T) t0=test[,1:4] t1=test[grep(tea,test$item1,ignore.case=FALSE),c(1,5)] t2=test[grep(tea,test$item2,ignore.case=FALSE),c(1,6)] tt=merge(t1,t2,by=id,all=T) hall=merge(t0,tt,by=id,all.tt=T) hall 範例9:水平和垂直合併(union) #method 2 : horizontal merge test=read.table(D:\\stella\\R\\input3.txt, header=T) l1=grep(tea,test[,5]) l2=grep(tea,test[,6]) t=test[union(l1,l2) ,] t[order(t$id),] # method 2 :vertical merge input=read.table(D:\\stella\\R\\input1.txt,header=T) input1=read.table(D:\\stella\\R\\input2.txt,header=T) (vall=rbind(input,input1)) dup=union(input$id,input1$id) (vall[dup, ]) 範例9:水平和垂直合併(union) 範例10:迴圈執行繪圖 # method 1:all files of one directory (dir=list.files(d:/stella/R/baby,full.name=TRUE)) # infile=dir[grep(“.txt”,dir)] par(mai=c(0.5,0.5,0.5,0.5),mfrow=c(3,4)) lbl=c(~20,20~25,25~30,30~35,35~40,40~) for (i in 1:length(dir)) { file0=dir[i]; data=read.table(file=file0,header=T) hist(data$bwt,main=paste(babies weight hist age=,lbl[i])) plot(data$height,data$weight,main=paste(height and weight plot age=,lbl[i])) } 範例10:迴圈執行繪圖 baby1.txt-baby6.txt對應先前用 subset函數輸出的檔grp1-grp6 範例10:迴圈執行繪圖 範例10:迴圈執行繪圖 #method 2:seqential file names利用循序檔名 pdf(d:\\stella\\R\\baby\\babies.pdf) # ,family=“GB1” par(mai=c(0.5,0.5,0.5,0.5),mfrow=c(3,2)) lbl=c(~20,20~25,25~30,30~35,35~40,40~) for (i in 1:6) { fn=paste(d:\\stella\\R\\baby\\baby,i,.txt,sep=); data=read.table(file=fn,header=T) hist(data$bwt,main=paste(babies weight hist age=,lbl[i])) plot(data$height,data$weight,main=paste(height and weight plot age=,lbl[i])) } graphics.off() # or dev.off() * R程式流程控制 結構化程式設計三種結構 : 循序sequential、選擇selection、重複iteration 各種程式範例說明 程式流程控制(branch) type I : if (logical condition TRUE) {statements1} type II : if (logical condition TRUE )

文档评论(0)

suijiazhuang1 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档