Skip to content

How do I get a weighted frequency table?

4 messages · Luca Meyer, Leandro Marino, David L Carlson

#
If you are talking about weights that are the frequencies in each cell, you
can use xtabs():

df <- data.frame(Var1=c("Absent", "Present", "Absent", "Present"), 
     Var2=c("Absent", "Absent", "Present", "Present"), Freq=c(17, 6, 3, 12))
df
xtabs(Freq~Var1+Var2, data=df)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Leandro Marino
Sent: Sunday, August 28, 2011 12:15 PM
To: Luca Meyer
Cc: r-help at r-project.org
Subject: Re: [R] How do I get a weighted frequency table?

*Luca,
*


you may use survey package. You have to declare the design with design
function and than you can you svytotal, svyby, svymean functions to do your
tabulations.

Regards,
Leandro



Atenciosamente,
Leandro Marino
http://www.leandromarino.com.br (Fotsgrafo)
http://est.leandromarino.com.br/Blog (Estatmstico)
Cel.: + 55 21 9845-7707
Cel.: + 55 21 8777-7907



2011/8/28 Luca Meyer <lucam1968 at gmail.com>

  
  
#
Hi David,

Unfortunately I need to use the "should have been" frequencies if the sample corresponded perfectly in terms of some "reference" variables to the population. 

That is, if in my sample I observe V1_R1=10%, V1_R2=50%, V3_R3=40% while the same known population distribution is V1_R1=20%, V1_R2=30%, V3_R3=50% then I would like to see what V2*V3, V2*V4, ... , V2* VN, V3*V4, ... ,VN-1 * VN would have been had the sample perfectly reflect the population in terms of V1.

I hope that clarifies what I am trying to achieve...

Thanks,
Luca

Il giorno 29/ago/2011, alle ore 16.29, David L Carlson ha scritto: