[R] Using Weights in R
Phil Spector
spector at stat.berkeley.edu
Fri Feb 18 02:08:52 CET 2011
Well, if you really want to produce what SAS does:
> ageval = read.table(textConnection('AgeCat FINWT
+ 1 98
+ 2 62
+ 1 75
+ 3 39
+ 4 28
+ 2 47
+ 2 66
+ 4 83
+ 1 19
+ 3 50
+ '),header=TRUE)
> one = aggregate(ageval$FINWT,ageval['AgeCat'],sum)
> two = prop.table(as.table(one$x)) * 100
> three = cumsum(one$x)
> four = cumsum(two)
> answer = data.frame(AgeCat=one$AgeCat,
+ Frequency=one$x,
+ Percent=as.numeric(two),
+ "Cumulative.Frequency"=three,
+ "Cumulative.Percent"=four)
> answer
AgeCat Frequency Percent Cumulative.Frequency Cumulative.Percent
A 1 192 33.86243 192 33.86243
B 2 175 30.86420 367 64.72663
C 3 89 15.69665 456 80.42328
D 4 111 19.57672 567 100.00000
You can probably find the specific part you want from the above code.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Thu, 17 Feb 2011, Krishnan Viswanathan wrote:
> I am new to R. I have a data set like this (given below is a fictional
> dataset):
>
> AgeCat FINWT
> 1 98
> 2 62
> 1 75
> 3 39
> 4 28
> 2 47
> 2 66
> 4 83
> 1 19
> 3 50
>
> I need to calculate the weighted distribution of the variable AgeCat.
>
> In SAS i can do:
>
> proc freq data=ageval;
> tables agecat;
> weight finwt;
> run;
>
> What or is there an equivalent in R?
>
> TIA,
> Krishnan
>
> --
> Krishnan Viswanathan
> 1101 High Meadow Dr
> Tallahassee FL 32311
>
> [[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.
>
More information about the R-help
mailing list