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

熱線電話:13121318867

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

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

一、R的變量類型

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

Vector: 一維陣列

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

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

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

List : 一個(gè)List中可包含多個(gè)類型對象,包括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ù)對結(jié)構(gòu)化的數(shù)據(jù)實(shí)現(xiàn)某些操作,對向量(vector)或者列表(list)按照元素或元素構(gòu)成的子集合進(jìn)行迭代。個(gè)人認(rèn)為相當(dāng)于一種批處理操作。

lapply(X, FUN, ...)

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

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

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

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


四、正則表達(dá)式(regular expression)

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

1.元字符(metacharacter)

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

常用元字符如下:


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


查詢功能的函數(shù)主要有g(shù)rep、grepl, 主要區(qū)別在于其輸出結(jié)果格式不同,共同點(diǎn)是都包含正則表達(dá)式pattern和文本X這兩個(gè)參數(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僅返回匹配項(xiàng)的下標(biāo),而grepl返回所有的查詢結(jié)果,并用邏輯向量表示有沒有找到匹配


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

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

sub(pattern, replacement, x)

gsub(pattern, replacement, x)


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

若不方便掃碼,搜微信號(hào):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(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) 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){ //倒計(jì)時(shí)完成 $(".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); }