Description Usage Arguments Note Author(s) Examples
This function calculates weights for each entity based on their expected
marketshares and number of observations. If a survey
is passed to the function,
a new column w
is added to the df
which contains a weight for all
the obserations. If a vector of types character
or factor
is
passed to the function, and the entities/ents from a survey, a numeric
vector is returned instead.
1 2 3 4 5 6 7 8 9 10 | add_weights(x, entities = NULL)
## S3 method for class 'survey'
add_weights(srv)
## S3 method for class 'character'
add_weights(x, ms)
## S3 method for class 'factor'
add_weights(x, ms)
|
x |
A survey object, or vector of type |
entities |
Optional: If a vector is passed to |
See add_entities
for information on the entities object.
Kristian D. Olsen
1 2 3 | x <- survey(data.frame("test" = 1, stringsAsFactors = FALSE))
x <- x %>% add_mm() %>% add_entities() %>% add_weights()
x %>% mutate(w = add_weights(q1, x$ents)) # i.e. create weights for subsets
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.