R保存用户定义的函数
我正在写一个小函数,给出一个条件密度和经验累积分布的组合图R保存用户定义的函数,r,sweave,R,Sweave,我正在写一个小函数,给出一个条件密度和经验累积分布的组合图 cdpl<-function(df,dep,indep){ attach(df) cdplot(dep~indep,xlab=deparse(substitute(indep)),ylab=deparse(substitute(dep))) g<-indep ec<-ecdf(indep) lines(knots(ec),as.numeric(names(table(ec(g)
cdpl<-function(df,dep,indep){
attach(df)
cdplot(dep~indep,xlab=deparse(substitute(indep)),ylab=deparse(substitute(dep)))
g<-indep
ec<-ecdf(indep)
lines(knots(ec),as.numeric(names(table(ec(g)))),col="red",lw=3)
detach(df)
}
cdpl不是附加(导致所有类型的问题),而是将数据帧作为数据参数传递到cdplot中,看看是否有效
<<fig1,fig=T>>=
par(mfrow=c(1,2))
print(cdpl(tre,A,B))
print(cdpl(tre,A,C))
@