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

熱線電話:13121318867

登錄
首頁精彩閱讀R語言 base包-apply函數(shù)_數(shù)據(jù)分析師
R語言 base包-apply函數(shù)_數(shù)據(jù)分析師
2014-11-07
收藏
R語言 base包-apply函數(shù)_數(shù)據(jù)分析師  

pply {base} R Documentation R文檔
 
Apply Functions Over Array Margins
對數(shù)組使用函數(shù)
 
Description描述
 
Returns a vector or array or list of values obtained by applying a function to margins of an array or matrix.
對一個(gè)數(shù)組或者矩陣框架使用一個(gè)函數(shù),并返回一個(gè)向量、陣列或者一個(gè)列表值
 
Usage用法
apply(X, MARGIN, FUN, ...)
 
Arguments參數(shù)
 
X
an array, including a matrix.
一個(gè)陣列:包括矩陣
 
MARGIN
a vector giving the subscripts which the function will be applied over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns. Where X has named dimnames, it can be a character vector selecting dimension names.
對于給定向量的描述,以提供給給定函數(shù)進(jìn)行計(jì)算。例如:1表示行,2表示列,c(1,2)表示行和列。x表示維數(shù),如果向量具有維名,可以用自符向量代替。
 
FUN
the function to be applied: see ‘Details’. In the case of functions like +, %*%, etc., the function name must be backquoted or quoted.
需要使用的函數(shù),見“細(xì)節(jié)”。諸如+、%*%這類函數(shù)的函數(shù)名需要加引號后者反引號。
...
optional arguments to FUN.
對于函數(shù)的可選參數(shù)
 
Details細(xì)節(jié)
 
If X is not an array but an object of a class with a non-null dim value (such as a data frame), apply attempts to coerce it to an array via as.matrix if it is two-dimensional (e.g., a data frame) or via as.array.
如果X不是一個(gè)矩陣,而是一個(gè)無維值得類對象,如:數(shù)據(jù)框,如果它是二維的話,apply()則嘗試通過as.matrix()強(qiáng)制轉(zhuǎn)換為陣列。
 
FUN is found by a call to match.fun and typically is either a function or a symbol (e.g. a backquoted name) or a character string specifying a function to be searched for from the environment of the call to apply.
FUN是一個(gè)可以通過調(diào)用match.fun()函數(shù)查看的函數(shù)、符號(反引號)或者能夠通過調(diào)用apply()從環(huán)境變量中搜索到的字符函數(shù)。
 
Value值
 
If each call to FUN returns a vector of length n, then apply returns an array of dimension c(n, dim(X)[MARGIN]) if n > 1. If n equals 1, apply returns a vector if MARGIN has length 1 and an array of dimension dim(X)[MARGIN] otherwise. If n is 0, the result has length 0 but not necessarily the ‘correct’ dimension.
如果每次調(diào)用函數(shù)返回一個(gè)長度為n的向量,那么apply()將會(huì)返回一個(gè)維數(shù)為c(n, dim(X)[MARGIN])的陣列。如果n>1,apply()將會(huì)返回一個(gè)向量。如果n為0,結(jié)果長度為0,但是沒有必要修正維數(shù)。
 
If the calls to FUN return vectors of different lengths, apply returns a list of length prod(dim(X)[MARGIN]) with dim set to MARGIN if this has length greater than one.
如果調(diào)用函數(shù)返回的是不同長度的向量,則返回一個(gè)維數(shù)為MARGIN(MARIGIN長度頁大于1)長度的列表,列表長度為prod(dim(X)[MARGIN])。
 
In all cases the result is coerced by as.vector to one of the basic vector types before the dimensions are set, so that (for example) factor results will be coerced to a character array.
在維數(shù)設(shè)定前,結(jié)果會(huì)由as.vector()強(qiáng)制轉(zhuǎn)換為一個(gè)基本向量類型。例如:因子結(jié)果會(huì)被轉(zhuǎn)換為一個(gè)字符陣列。
 
References參考文獻(xiàn)
 
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
 
See Also也可參見
 
lapply and there, simplify2array; tapply, and convenience functions sweep and aggregate.
 
Examples
## Compute row and column sums for a matrix:
x <- cbind(x1 = 3, x2 = c(4:1, 2:5))    #按照列組合3和c(4:1,2:5)列表
dimnames(x)[[1]] <- letters[1:8]    #將x的行維名字修改為a-h
apply(x, 2, mean, trim = .2)    #用apply()調(diào)用,對列求均值,求均值前除去最大最小的20%部分
col.sums <- apply(x, 2, sum)  #對列求和
row.sums <- apply(x, 1, sum)  #對行求和
rbind(cbind(x, Rtot = row.sums), Ctot = c(col.sums, sum(col.sums)))
 
stopifnot( apply(x, 2, is.vector))
 
## Sort the columns of a matrix
apply(x, 2, sort)
 
##- function with extra args:
cave <- function(x, c1, c2) c(mean(x[c1]), mean(x[c2]))
apply(x,1, cave,  c1="x1", c2=c("x1","x2"))
 
ma <- matrix(c(1:4, 1, 6:8), nrow = 2)
ma
apply(ma, 1, table)  #--> a list of length 2
apply(ma, 1, stats::quantile)# 5 x n matrix with rownames
 
stopifnot(dim(ma) == dim(apply(ma, 1:2, sum)))
 
## Example with different lengths for each call
z <- array(1:24, dim=2:4)
zseq <- apply(z, 1:2, function(x) seq_len(max(x)))
zseq         ## a 2 x 3 matrix
typeof(zseq) ## list
dim(zseq) ## 2 3
zseq[1,]
apply(z, 3, function(x) seq_len(max(x)))
# a list without a dim attribute
 
 
--------------------------------------------------------------------------------
 
[Package base version 2.15.1 Index] 

數(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(), // 加隨機(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, // 表示用戶后臺檢測極驗(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); }