【问题标题】:R Sweave user defined functionR Sweave 用户定义函数
【发布时间】:2010-09-02 18:28:53
【问题描述】:

我正在编写一个小函数,给出组合条件密度和经验累积分布图。

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)
    }

这很好用,但是当我尝试编织它时,我的运气已经全部耗尽......

<<fig1,fig=T>>=
par(mfrow=c(1,2))
print(cdpl(tre,A,B))
print(cdpl(tre,A,C))
@

Sweave("re.rnw") 写入文件 re.tex 处理代码块...

1 : 逐字回显 eps pdf (label=fig1)

错误:块 1 (label=fig1) model.frame.default(formula = dep ~ indep) 中的错误: 变量“dep”的类型(列表)无效

如果它在 sweave 之外可以正常工作,这怎么可能?

//M

【问题讨论】:

    标签: r sweave


    【解决方案1】:

    而不是附加(导致所有类型的问题)将数据框作为数据参数传递给 cdplot 并查看是否有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      相关资源
      最近更新 更多