make.unique:
Description
Makes the elements of a character vector unique by appending sequence numbers to duplicates
Usage
make.unique(names, sep = ".")
Example
make.unique(c("a", "a", "a"))
choose:
The functions choose and lchoose return binomial coefficients and the logarithms of their absolute values. Note that choose(n, k) is defined for all real numbers n and integer k. For k ≥ 1 it is defined as n(n-1)…(n-k+1) / k!, as 1 for k = 0 and as 0 for negative k. Non-integer values of k are rounded to an integer, with a warning.
choose(5, 2)#5个球中抓两个的所有可能性
do.call:可以通过文本调用函数
Description
do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it.
Usage
do.call(what, args, quote = FALSE, envir = parent.frame())
Arguments
what
either a function or a non-empty character string naming the function to be called.
args
a list of arguments to the function call. The names attribute of args gives the argument names.
quote
a logical value indicating whether to quote the arguments.
envir
an environment within which to evaluate the call. This will be most useful if what is a character string and the arguments are symbols or quoted expressions.
example:
do.call(paste, list(as.name("A"), as.name("B")), quote = TRUE)
eval,parse (字符串声明函数):将文本转化为命令
example:
eval(parse(text = "sum(1:5)+1"))
参考链接:https://blog.csdn.net/qq_27755195/article/details/62892756
system.time+proc.time:计算程序的运行时间
使用方法:system.time({function})
结果:
“用户”时间指运行此程序使用CPU的时间,它不包括此阶段内计算机其它进程的时间(比如开的杀毒软件等等)
”系统”时间指程序中的一些诸如打开、关闭文件,分配、释放内存,执行系统指令等等的CPU时间,也不包括其它进程占用的时间
“流逝”时间则指实际执行时间。当单线程执行程序时,前两者之和约等于(略小于)第三者。而当多线程时,第三者可能小于甚至远小于前两者之和
常见的计算执行时间的代码:
t1=proc.time()
#程序体
t2=proc.time()
t=t2-t1
print(paste0('执行时间:',t[3][[1]],'秒'))
网友评论