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

熱線電話:13121318867

登錄
首頁精彩閱讀R語言做數(shù)據(jù)探索
R語言做數(shù)據(jù)探索
2017-06-09
收藏

R語言數(shù)據(jù)探索

1 數(shù)據(jù)導入

數(shù)據(jù)常用格式.csv/.txt/.xls/.json/.xml。
R語言提供相應的函數(shù)和庫實現(xiàn)對這些數(shù)據(jù)格式的導入。
現(xiàn)已導入.csv格式和以tab分隔的.txt格式為例

# 讀.csv格式

data1<-read.csv(file='C:/abc.csv',header=TRUE,sep=',')


# 讀以tab分隔的.txt格式

data2<-read.csv(file='C:/abc.txt',header=TRUE,sep='\t')

2 數(shù)據(jù)類型變換

數(shù)據(jù)類型變換包括數(shù)據(jù)類型測試和數(shù)據(jù)類型之間的變換。
數(shù)據(jù)類型測試采用is.xyz系列函數(shù),該函數(shù)測試是否為某一種數(shù)據(jù)類型,返回值是邏輯類型,即TRUE和FALSE。
數(shù)據(jù)類型變換采用as.xyz系列函數(shù),把某一種數(shù)據(jù)類型變換到另一種數(shù)據(jù)類型。
例如:

is.numeric(),is.character(),is.vector(),is.matrix(),is.data.frame()

as.numeric(),as.character(),as.vector(),as.matrix(),as.data.frame()

R語言數(shù)據(jù)結構之間的轉換

3 數(shù)據(jù)集變換

數(shù)據(jù)轉換成窄數(shù)據(jù),例如:

R語言把寬數(shù)據(jù)集變換成窄數(shù)據(jù)集

library(reshape)

data3<-melt(mydata,id=c("id","time"))4 數(shù)據(jù)排序

利用order函數(shù)對單一變量或者多個變量進行排序(升序或者降序),返回具有排序功能的索引位置。

# sort by var1

data4<-old[order(var1),]

# sort by var1 and var2 (descending)

data5<-old[order(var1,-var2),]

5 數(shù)據(jù)可視化

利用R語言做數(shù)據(jù)可視簡單和高效。

R語言畫直方圖

set.seed(1234)

score<-rnorm(n=1000,m=80,sd=20)

hist(score)

直方圖上面添加密度曲線

hist(score,

freq=FALSE,

xlab="Score",

main="Distribution of score",

col="lightgreen",

xlim=c(0,150),

ylim=c(0,0.02))

curve(dnorm(x,

mean=mean(score),

sd=sd(score)),

add=TRUE,

col="darkblue",

lwd=2)

6 列聯(lián)表

列聯(lián)表是理解各類分布的最基本和最有效的方式。

單變量列聯(lián)表

多變量列聯(lián)表
參考代碼

library(gmodels)

CrossTable(mydata$myrowvar,mydata$mycolvar)

7 數(shù)據(jù)抽樣

利用sample函數(shù)實現(xiàn)數(shù)據(jù)抽樣
從數(shù)據(jù)集中不放回地隨機抽取100個樣本
參考代碼:

mysample<-mydata[sample(1:nrow(mydata),100,replace=FALSE),]

8 數(shù)據(jù)去重

利用unique函數(shù)去掉向量中的重復值

set.seed(1234)

x<-round(rnorm(20,10,5))

x

unique(x)

結果如下

9 數(shù)據(jù)匯總

使用apply系列函數(shù),實現(xiàn)匯總

10 缺失值識別和處理

使用is.na函數(shù)識別缺失值,采用均值、中位數(shù)、眾數(shù)、插補法等方法對確實值處理。

y<-c(4,5,6,NA)

is.na(y)

y[is.na(y)]<-mean(y,na.rm=TRUE)

y

11 異常值識別和處理

異常值識別-異常值定位-異常值處理
異常值識別方法:盒箱圖和簡單統(tǒng)計量
異常值處理方法:剔除法/修復法

12 數(shù)據(jù)合并

利用merge函數(shù)或者rbind函數(shù)或者sqldf包基于數(shù)據(jù)庫的連接操作

# merge two data frames by ID

total<-merge(data frameA,data frameB,by="ID"

# merge two data frames by ID and Country

total<-merge(data frameA,data frameB,by=c("ID","Country"))

total<-rbind(data frameA,data frameB)

總結

本文總結了R語言數(shù)據(jù)探索和處理的知識。

數(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(); // 調用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調,回調的第一個參數(shù)驗證碼對象,之后可以使用它調用相應的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務器是否宕機 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); }