2011-08-16 51 views
5

我的代碼在運行時沒有問題,在調用dcast公式時崩潰。玩過之後,我發現即使是來自dcast幫助頁面的最小例子也不再適用於我。更確切地說:從reshape2幫助頁面運行示例的錯誤消息

#Air quality example 
names(airquality) <- tolower(names(airquality)) 
aqm <- melt(airquality, id=c("month", "day"), na.rm=TRUE) 

acast(aqm, day ~ month ~ variable) 
acast(aqm, month ~ variable, mean) 

最後一行產生以下錯誤:

Error in vaggregate(.value = value, .group = overall, .fun = fun.aggregate, : 
    could not find function ".fun" 

這裏是我的sessionInfo():

R version 2.13.1 (2011-07-08) 
Platform: x86_64-pc-mingw32/x64 (64-bit) 

locale: 
[1] C 

attached base packages: 
[1] grid  stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] ggplot2_0.8.9 proto_0.3-9.2 reshape2_1.1 xtable_1.5-6 reshape_0.8.4 plyr_1.5.2  lubridate_0.2.5 

loaded via a namespace (and not attached): 
[1] stringr_0.5 tools_2.13.1 

我不拿出一個令人滿意的答案這裏出了什麼問題,所以我希望得到一些幫助。此外,我在這裏找到以下線程在計算器上:Similar problem 此問題似乎是由自定義函數引起的。但是,我使用標準平均函數和幫助頁面中的標準示例。

更新:我剛做了一些互聯網調查,但沒有找到關於reshape2軟件包更新的任何信息。這是我對這個問題的最好猜測。

UPDATE2:問題發生是因爲我在R會話期間玩弄了一個靜態示例時,很可能重新分配了平均函數。重新啓動R解決了這個問題。現在,一切都按預期再次運作。

+0

這將運行對我很好,唯一明顯的差別,我可以之間看到我們系統是我在OS X上。 – joran

+1

對我來說運行良好。我在win64上也有R 2.13.1 ... search()的輸出是什麼? – Tommy

+0

對我來說,Fedora 14 Linux也可以運行,使用'plyr_1.5.2 stringr_0.5 tools_2.13.1','reshape2_1.1'和'R version 2.13.1 Patched(2011-07-13 r56380)'。 –

回答

5

出於完整性:

PaulHurleyuk的評論:

Have you tried restarting R and trying the example in a fresh session ? Or do rm(list=ls()) to remove everything from the current session. In the past I have managed to break things by assigning something to something that shouldn't be assigned to.

Christoph_J的迴應:

Thanks ... that was exactly the problem...

The problem occurred because I most probably reassigned the mean function while I was playing around with a statisctic example during an R session. Restarting R solved the problem. Now, everything works as expected again.