Skip to content

Weighted descriptives by levels of another variables

4 messages · Andrew Miles, David Winsemius, David Freedman

#
Have you reviewed the survey package functions?
#
In addition to using the survey package (and the svyby function), I've found
that many of the 'weighted' functions, such as wtd.mean, work well with the
plyr package.  For example, 

wtdmean=function(df)wtd.mean(df$obese,df$sampwt);
ddply(mydata, ~cut2(age,c(2,6,12,16)),'wtdmean')

hth, david freedman
Andrew Miles-2 wrote:

  
    
#
In addition to using the survey package (and the svyby function), I've found
that many of the 'weighted' functions, such as wtd.mean, work well with the
plyr package.  For example, 

wtdmean=function(df)wtd.mean(df$obese,df$sampwt);
ddply(mydata, ~cut2(age,c(2,6,12,16)),'wtdmean')

hth, david freedman
Andrew Miles-2 wrote: