parApply、parApply、parSapply是parallel包里面的
apply、lapply、sapply是base包里面自带的。
parApply、parApply、parSapply分别是apply、lapply、sapply的并行运算版本。对应的方法输出结果和使用方式相同,是不过par-需要设定核数(或者使用默认核数计算)
margin
目录
Apply Functions Over Array Margins
Apply a Function over a List or Vector
3.sapply,vapplysapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
vapply(X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE)
replicate(n, expr, simplify = "array")
simplify2array(x, higher = TRUE)
Apply Operations using Clusters
parLapplyparLapply returns a list the length of X.
1.apply 对象为数组
apply {base} | R Documentation |
Apply Functions Over Array Margins
Description
Returns a vector or array or list of values obtained by applying a function to margins of an array or matrix.
Usage
apply(X, MARGIN, FUN, ...)
apply(对象,行/列,功能函数)
Arguments
X |
an array, including a matrix. 要处理的数组对象 |
MARGIN |
a vector giving the subscripts which the function will be applied over. E.g., for a matrix |
FUN |
the function to be applied: see ‘Details’. In the case of functions like |
... |
optional arguments to |
example:
a<-array(1:90000,dim = c(100,900))
apply(a,1,sd) #对每一行求sd
system.time(apply(a,1,sd)) #计算运行时间,可以用来比较速度
2.lapply 对象为向量
lapply {base} | R Documentation |
Apply a Function over a List or Vector
lapply(X, FUN, ...) #因为对象是列表或向量,所以不需要用margin来指定是行或者是列了
x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))
#