Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aggregate function produces error after loading memisc package

Tags:

r

aggregate function works fine

aggregate(weight ~ feed, data = chickwts, mean)
       feed   weight
1    casein 323.5833
2 horsebean 160.2000
3   linseed 218.7500
4  meatmeal 276.9091
5   soybean 246.4286
6 sunflower 328.9167

But after loading library(memisc) in R 2.14.1, the same code produces the following error

Error in `[.default`(xj, i) : invalid subscript type 'closure'

What is the problem and how to solve this? Thanks in advance for your help.

like image 838
MYaseen208 Avatar asked Nov 20 '25 04:11

MYaseen208


1 Answers

This package redefines the aggregate method. There is often a warning in those cases, but since aggregate.formula is a hidden method, there is no warning. You can explicitely use the initial aggregate function by specifying its namespace (three colons are needed because it is a hidden method).

stats:::aggregate.formula(weight ~ feed, data = chickwts, mean)
like image 62
Vincent Zoonekynd Avatar answered Nov 21 '25 18:11

Vincent Zoonekynd