TyagiAnupam@aol.com
2003-Sep-20 01:55 UTC
[R] using aggregate with survey-design and survey functions
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 [[alternative HTML version deleted]]
Spencer Graves
2003-Sep-20 02:47 UTC
[R] using aggregate with survey-design and survey functions
What do you get from the following:
is.element("income", objects())
spencer graves
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
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
TyagiAnupam@aol.com
2003-Sep-20 02:52 UTC
[R] using aggregate with survey-design and survey functions
In a message dated 9/19/03 7:46:07 PM Pacific Daylight Time, spencer.graves@pdf.com writes:> What do you get from the following: > > is.element("income", objects()) > > spencer graves >> is.element("income", objects())[1] FALSE The following may give further info about why I am getting this. Design object is "d.na"> attributes(d.na)$names [1] "cluster" "strata" "prob" "allprob" "call" "variables" [7] "nPSU" $class [1] "survey.design" [[alternative HTML version deleted]]
Thomas Lumley
2003-Sep-20 16:19 UTC
[R] using aggregate with survey-design and survey functions
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 foundThis 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. -thomas
TyagiAnupam@aol.com
2003-Sep-20 17:56 UTC
[R] using aggregate with survey-design and survey functions
In a message dated 9/20/03 9:19:57 AM Pacific Daylight Time, tlumley@u.washington.edu writes:> 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.Thanks for the info. I tried looking at source code of aggregate, but it only points to UseMethod("aggregate"). How can I find the source of this method? --anupam. [[alternative HTML version deleted]]