Learn R Programming

weights (version 1.1.1)

wpct: Provides a weighted table of percentages for any variable.

Description

wpct produces a weighted table of the proportion of data in each category for any variable. This is simply a weighted frequency table divided by its sum.

Usage

wpct(x, weight=NULL, na.rm=TRUE, ...)

Value

A table object of length equal to the number of separate values of x.

Arguments

x

x should be a vector for which a set of proportions is desired.

weight

weight is a vector of weights to be used to determining the weighted proportion in each category of x.

na.rm

If na.rm is true, missing data will be dropped. If na.rm is false, missing data will return an error.

...

... (optional) Additional arguments to be passed on to wtd.table.

Author

Josh Pasek, Professor of Communication & Media and Political Science at the University of Michigan (www.joshpasek.com).

Examples

Run this code
test <- c(1,1,1,1,1,1,2,2,2,3,3,3,4,4)
weight <- c(.5,.5,.5,.5,.5,1,1,1,1,2,2,2,2,2)

wpct(test)
wpct(test, weight)

Run the code above in your browser using DataLab