Add a weight variable using the sample frame
add_weights.Rd
Add a weight variable using the sample frame
Usage
add_weights(
dataset,
sample_data,
strata_column_dataset = NULL,
strata_column_sample = NULL,
population_column = NULL,
weight_column = "weights"
)
Arguments
- dataset
the clean dataframe
- sample_data
sample dataframe including poplution numbers and the strata
- strata_column_dataset
name of strata column in the clean dataframe
- strata_column_sample
name of strata column in the sample dataframe
- population_column
name of population column in the sample dataframe
- weight_column
name of the added weight column. By default "weights"
Examples
clean_data <- data.frame(
uuid = c(1, 2, 3, 4, 5, 6, 7, 8),
strata = c(
"strata1", "strata2", "strata1",
"strata2", "strata1", "strata2",
"strata1", "strata1"
)
)
sample <- data.frame(
strata = c("strata1", "strata2"),
population = c(30000, 50000)
)
clean_data_weighted <- clean_data %>%
add_weights(sample,
strata_column_dataset = "strata",
strata_column_sample = "strata",
population_column = "population"
)