View source: R/helper.functions.r
wtd.mean | R Documentation |
Takes in variable and calculates its mean, works with sampling weights.
Makes use of the wtd.mean function, part of the Hmisc package. See wtd.stats
documentation for details.
wtd.mean(x, w = NULL, data, digits = 3, ...)
x |
A variable (must be numeric), should be in dataset$var form unless dataset specified in optional data argument. |
w |
(Optional) Sampling weights of variable, must be numeric; should be in dataset$weightvar form unless dataset specified in optional data argument. |
data |
(Optional) Name of dataset that contains x (and w) variable. |
digits |
(Optional) Number of decimal places reported in result (defaults to 3). |
... |
(Optional) Additional arguments passed to Hmisc::wtd.mean function. |
Returns the mean of the variable, a numeric value.
library(RCPA3)
wtd.mean(nes$ft.socialists, w=nes$wt)
wtd.mean(nes$ft.socialists)
wtd.mean(nes$age, w=nes$wt)
wtd.mean(nes$age)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.