[R] WEIGHT CASES by Frequency VECTOR
P.Dalgaard at biostat.ku.dk
Tue Nov 25 15:03:25 CET 2008
sharon Wandia wrote:
> Does anyone know how to weight cases in a data frame using a frequency
> I'm trying to run tabulations on R , on a data set that first needs to have
> weighted cases before i run the tabulations.
> In SPSS & SAS its quite simple, but i'm unable to do it in R.
xtabs() allows a count on the LHS of its formula argument, if you're
looking at contingency tables. In other cases, an expedient, if
inefficient, trick is simply to expand your data using rep(), i.e.
mydata.x <- mydata[rep(1:nrow(mydata),mydata$count),]
(Re. SPSS & SAS: what is not quite as simple is to see whether weights
are frequency weights or variance weights.)
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help