jianfengmao的个人博客分享 http://blog.sciencenet.cn/u/jianfengmao

博文

记着用 lapply(base)

已有 5525 次阅读 2010-7-21 08:50 |个人分类:R and Statistics|系统分类:科研笔记|关键词:学者| lapply

在R里做循环操作,似乎可以放弃 for 这样的循环语句。lapply(base) 应该是首选途径。事实上lapply(base)是个家族。让我们看看它们的成员与用法:

Description (描述)
lapply 
returns a list of the same length as X, each element of which is the    result of applying FUN to the corresponding element of X. 

sapply 
is a user-friendly version of lapply by default returning a vector or matrix if appropriate. 

replicate 
is a wrapper for the common use of sapply for repeated evaluation   of an expression (which will usually involve random number generation). 

Usage (用法)
lapply(X, FUN, ...)

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

replicate(n, expr, simplify = TRUE)

Arguments (参数设置)


a vector (atomic or list) or an expressions vector. Other objects (including classed objects) will be coerced by as.list. 
FUN the function to be applied to each element of X: see ‘Details’. In the case of functions like +, %*%, etc., the function name must be backquoted or quoted. 

... optional arguments to FUN. 

simplify logical; 
should the result be simplified to a vector or matrix if possible?
 
USE.NAMES logical; 
if TRUE and if X is character, use X as names for the result unless it had names already. 


number of replications. 

expr 
expression (language object, usually a call) to evaluate repeatedly. 



https://m.sciencenet.cn/blog-352360-345949.html

上一篇:强大的,做permutation test的R包 - perm
下一篇:记着用 ddply(plyr)

0

发表评论 评论 (1 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-2 11:04

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部