2010-09-02 104 views
3

我正在編寫一個小函數,給出一個組合條件密度和經驗累積分佈圖。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)))),col="red",lw=3) 
    detach(df) 
    } 

這工作得很好,但是當我嘗試sweave它我的運氣是全力以赴......

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

Sweave("re.rnw") Writing to file re.tex Processing code chunks ...

1:回聲長期逐字EPS PDF(標籤= FIG1)

錯誤:塊1(標籤= fig1) model.frame.default(公式= dep〜indep)中的錯誤: 變量'dep'的無效類型(列表)

這怎麼可能當它在外面工作時完全正常?

//中號

回答

1

代替附接(導致所有類型的問題)傳遞數據幀作爲cdplot數據參數,並看是否可行。

+0

那肯定有幫助...... Thx – Misha 2010-09-02 19:33:17