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

熱線電話:13121318867

登錄
首頁精彩閱讀在R中整理數(shù)據(jù)
在R中整理數(shù)據(jù)
2017-05-23
收藏

在R中整理數(shù)據(jù)

原始數(shù)據(jù)一般分散雜亂,并含有缺失和錯誤值,因此在進行數(shù)據(jù)分析前首先要對數(shù)據(jù)進行整理。

一、首先,了解原始數(shù)據(jù)的結(jié)構(gòu)。

可使用如下函數(shù)(歸屬baseR)來查看數(shù)據(jù)結(jié)構(gòu):

class(dataobject)  查看數(shù)據(jù)對象的類別

dim(dataobject)  查看數(shù)據(jù)的維度

names(dataobject)  查看列名 

str(dataobject) 查看數(shù)據(jù)概要

glimpse(dataobject) 查看數(shù)據(jù)概要

二、將數(shù)據(jù)變得整潔
可使用下列函數(shù)(歸屬package: tidyr)整理數(shù)據(jù):
1.  gather(data, key, value, -col )   將多個列收緊成關(guān)鍵列值,寬數(shù)據(jù)變成長數(shù)據(jù)。
2.  spread(data, key, value)      將關(guān)鍵列值擴展成多個列,長數(shù)據(jù)變成寬數(shù)據(jù)。
3. separate(data, col, into, sep = "")  將一列分成多列。
4. unite(data, col, ..., sep = "")   將多列合成一列。
雜亂數(shù)據(jù)的特征和對應(yīng)處理函數(shù):
1.列名是值(value)而不是變量(variable)  ---gather
2.變量同時存在行和列中 ---spread
3.多個變量位于同一列   ---seperate
4.單個觀測值位于多張數(shù)據(jù)表中,多個類型單元位于同張數(shù)據(jù)表 ---seperate+unite
三、準(zhǔn)備用于分析的數(shù)據(jù)
1.數(shù)據(jù)的類別如下,可調(diào)用class()查看數(shù)據(jù)的類別,也可使用as.numeric()、as.factor()等函數(shù)來轉(zhuǎn)換類別。

character

numeric

integer

factor

logical


2.對日期和時間的處理

需裝載的package:lubridate

調(diào)用的函數(shù):ymd_hms(), ymd()等。 ymd_hms 對應(yīng):年月日_時分秒

例子:

> dmy("17 Sep 2015")
[1] "2015-09-17"

3.字符串的處理

需裝載的package:library(stringr)

調(diào)用的函數(shù):

str_pad(string, width, side = c("left", "right", "both"), pad = " ")   填充字符串
str_trim(string)     清除字符串首尾空格
str_detect(string, pattern)    檢測字符串中是否存在某個pattern
str_replace(string, pattern, replacement)   替代字符串中匹配的pattern
na.omit(df)   移除有缺失值的行
complete.cases(df)    查看沒有缺失值的行
下面兩個字符處理函數(shù)在baseR中
toupper(string)  轉(zhuǎn)換成大寫
tolower(string)  轉(zhuǎn)換成小寫
4.  缺失值和特殊值(miss and special value)
在R中,缺失值一般用NA表示。特殊值有 Inf(無窮值)、NaN(not a number)。
查看數(shù)據(jù)中是否有NA:   
is.na(data)
any(is.na(data))
查看數(shù)據(jù)中沒有缺失值的行:complete.cases(data)
在數(shù)據(jù)中移除有缺失值的行:na.omit(data)
5.處理數(shù)據(jù)中的異常值和明顯錯誤
常用summary() 和 hist() 函數(shù)來確認(rèn)異常值(或極端值)


數(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); }