[R] How do I get a weighted frequency table?

David L Carlson dcarlson at tamu.edu
Mon Aug 29 16:29:07 CEST 2011


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>

> Hello,
>
> I have to run a set of crosstabulations to which I need to apply some 
> weights. I am currently doing an unweighted version of such crosstabs 
> using table(x,y).
>
> I am used with SPSS to create a weighting variable and to use WEIGHT 
> BY VAR before running the CTABLES, is there a similar procedure in R?
>
> Thanks,
> Luca
>
> Mr. Luca Meyer
> www.lucameyer.com
> R version 2.13.1 (2011-07-08)
> Mac OS X 10.6.8
>
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list