99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀R語言學習-基礎(chǔ)篇
R語言學習-基礎(chǔ)篇
2017-02-17
收藏

R語言學習-基礎(chǔ)篇

從2月10日開始自學R in action,將我的學習所得逐漸發(fā)布在這。

                                 chapter1.新手上路

工作空間:存儲著所有用戶定義的對象(向量,矩陣,函數(shù),數(shù)據(jù)框,列表);

當前的工目錄保存是R用來讀取文件和保存結(jié)果的默認目錄。

getwd()顯示當前工作目錄;

setwd(“”)修改當前的工作目錄;工作目錄的"\"要換成“/”;歷史記錄保存在文件.Rhistory中,工作空間保存在文件.RData中。

install.packages("")下載某個包,library();載入某個包;

包使用方法的查詢:help(package="package_name");

 

                                      chapter2創(chuàng)建數(shù)據(jù)集

1.不同的行業(yè)對數(shù)據(jù)集行和列的叫法:

統(tǒng)計學家:觀測和變量

2.R中的數(shù)據(jù)結(jié)構(gòu)

標量,向量,矩陣,數(shù)組,數(shù)據(jù)框,列表

(1)向量------------------->數(shù)組 (區(qū)別:c中數(shù)組是從0開始計數(shù)的,R是從1開始)

a<-c(1,2,3,4)

a[3](和c類似呢)

a[(c(1,2,4))]  #訪問1,2,,4號元素

a[2:4]

(2)矩陣--------------------》二維數(shù)組

mymatrix<-matrix(1:20,nrow=5,ncol=4)

cells<-c(1,26,24,56)

rnames<-c("r1","r2")

cnames<-c("c1","c2")

mymatrix<-matrix(cells,nrow=2,ncol=2,byrow=true,dimnames=list(rnames,cnames))        byrow=true 按行填充    false 按列填充

矩陣下標使用

x[1,2]

x[1,]

x[,2]

x[1,c(1,2)] 

(3)數(shù)組與矩陣類似,但是維度可以大于2

(4)數(shù)據(jù)框

mydata<-data.frame(col1,col2,col3)

選取數(shù)據(jù)框的元素

mydata[1:2]

mydata$coln      $的作用類似與c中的.

(5)列表

一些對象的有序集合

2.數(shù)據(jù)的輸入

1.從鍵盤輸入

edit()函數(shù)會自動調(diào)用一個允許從鍵盤輸入的文本編輯器

mydata<-dataframe(age=numeric(0),gender=charactor(0),weight=numeric(0))

mydata<-edit(mydata)   edit實際上是在對象的一個副本上操作,需要賦值到一個目標上

2.從帶分隔符的文本文件導入數(shù)據(jù)

>mydataframe<-read.table("myfile.csv",header=TRUE,sep=",",row.names="id")
> mydataframe
grade
1 23
2 23
3 12
4 32
5 12
> mydataframe<-read.table("myfile.csv",header=TRUE,sep=",")
> mydataframe
id grade
1 1 23
2 2 23
3 3 12
4 4 32
5 5 12

3.訪問數(shù)據(jù)庫管理系統(tǒng)

需要先安裝ODBC驅(qū)動,注冊數(shù)據(jù)源名稱,用戶名以及密碼。

myconn<-odbcConnect("**",uid="**",pwd="**")

crimedat<-sqlFetch(myconn,Crime)

                                              chapter3圖形初階

>opar<-(no.readonly=TRUE)---------------------------保存當前圖形設(shè)置參數(shù)

> par(pin=c(2,3))---------------得到的圖形大小為兩英尺寬,三英尺高
> par(cex.axis=0.75,font.axis=3)-------------------坐標軸刻度設(shè)置為斜體,0.75倍
> par(lwd=2,cex=1.5)---------------線條為默認寬度2倍,符號1.5倍
> plot(dose,drugA,type="b",pch=19,lty=2,col="red")
> plot(dose,drugB,type="b",pch=19,lty=2,col="blue",bg="green")這兩幅圖都遵循par的設(shè)置

>par(opar)----------------------還原

可以使用title函數(shù)為圖形添加標題和坐標軸標簽

使用axis函數(shù)創(chuàng)建自定義坐標軸

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }