[R] using aggregate with survey-design and survey functions
tlumley at u.washington.edu
Sat Sep 20 18:19:52 CEST 2003
On Fri, 19 Sep 2003 TyagiAnupam at aol.com wrote:
> Hi R users,
> I am trying to use the aggregate function with a survey design object and
> survey functions, but get the following error. I think I am incorrectly using the
> syntax somehow, and it may not be possible to access variables directly by
> name in a survey-design object. Am I right? How do I fix this problem? I have
> used aggregate with "mean" and "weighted.mean", and that works fine. I am trying
> to find out where the difference is. What would be an efficient alternative
> to aggregate for a large dataset?
> > s <- aggregate(income,list(age,sex),function(x) (svymean(~x,design=d.na)))
> Error in aggregate(income, list(age, sex), function(x) (svymean(~x, :
> Object "income" not found
This isn't going to work.
svymean needs the survey metadata to get the right mean, and aggregate
doesn't give it enough information. aggregate would need a separate
method for svydesign objects.
More information about the R-help