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

熱線電話:13121318867

登錄
首頁精彩閱讀R的變量類型和常用函數(shù)
R的變量類型和常用函數(shù)
2017-05-23
收藏

R的變量類型和常用函數(shù)

一、R的變量類型

也可以說是數(shù)據(jù)存儲方式,有:

Vector: 一維陣列

Matrics: 二維陣列,其中所有元素是同一數(shù)據(jù)類型。

factor: 種類變量,可使用levels函數(shù)來規(guī)定種類變量的各級別的名稱。例如:levels(factor_vector) <- c("name1", "name2",...)

Dataframe:二維陣列,每一列中的元素是同一數(shù)據(jù)類型,不同列的數(shù)據(jù)類型可以不同。

List : 一個List中可包含多個類型對象,包括List本身。


二、常用函數(shù)

seq(from,to,by):  Generate sequences, by specifying the from, to and by arguments.
rep():   Replicate elements of vectors and lists.
sort():   Sort a vector in ascending order. Works on numerics, but also on character strings and logicals.
rev():   Reverse the elements in a data structures for which reversal is defined.
str():    Display the structure of any R object.
append():   Merge vectors or lists.
is.*():     Check for the class of an R object.
as.*():    Convert an R object from one class to another.
unlist():   Flatten (possibly embedded) lists to produce a vector.


三、apply函數(shù)家族

通過apply函數(shù)對結構化的數(shù)據(jù)實現(xiàn)某些操作,對向量(vector)或者列表(list)按照元素或元素構成的子集合進行迭代。個人認為相當于一種批處理操作。

lapply(X, FUN, ...)

sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)

lapply和sapply將一個函數(shù)應用于一個list或者vector, 區(qū)別在于lapply以列表(list)形式返回結果,而sapply將輸出結果簡化為一個向量或者矩陣。

vapply(X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE)

vapply類似于sapply,但是提供了參數(shù)FUN.VALUE用以指明返回值的形式,即返回值可以有預定義類型,因此更安全。


四、正則表達式(regular expression)

正則表達式不是R的專屬內(nèi)容,用于描述/匹配一個文本集合的表達式。通常被用來檢索、替換那些符合某個模式(規(guī)則)的文本。

1.元字符(metacharacter)

一些特殊的字符在正則表達式中不在用來描述它自身,它們在正則表達式中已經(jīng)被“轉義”,這些字符稱為元字符。

常用元字符如下:


2、字符串匹配查詢函數(shù)


查詢功能的函數(shù)主要有grep、grepl, 主要區(qū)別在于其輸出結果格式不同,共同點是都包含正則表達式pattern和文本X這兩個參數(shù)。

grepl(pattern, x)    which returns TRUE when a pattern is found in the corresponding character string.

grep(pattern, x)    which returns a vector of indices of the character strings that contains the pattern.

grep僅返回匹配項的下標,而grepl返回所有的查詢結果,并用邏輯向量表示有沒有找到匹配


3、字符串替換函數(shù)

模式替換函數(shù)主要有sub和gsub,二者的區(qū)別在于sub函數(shù)只替換文本中第一個匹配的元素,gsub則針對X中所有匹配元素。

sub(pattern, replacement, x)

gsub(pattern, replacement, x)


數(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)用相應的接口 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); }