trace函数:修改部分可见函数的源代码。
自定义函数:函数名<-function(){ }
#修改函数源代码
trace(函数名称,edit=T)
#取消修改函数源代码
untrace(函数名称)
#自定义函数
fun_1<-function(x,old,new){
n<-length(x)
for(i in 1:n){
if(x[i]==old){
x[i]<-new
}
}
return(x)
}
#匿名函数
(function(x){x+6})(100)
#闭包
power<-function(x){
function(y){
y^x
}
}
#函数列表
fun_ls<-list(mean,max,var,min)
①自定义函数

②匿名函数

③闭包

④函数列表

网友评论