Skip to contents

Get most popular location for each activity, possibly with stratification.

Usage

get_most_popular_locn(tus_dat, col_nm, missing_ids, strata = NULL)

Arguments

tus_dat

A data frame of the time use survey data. This is expected to be in the format saved by run_data_prep_tus().

col_nm

A character string: name of new column to create which will hold the most popular location for each activity (possibly by strata).

missing_ids

An integer vector of the numeric id's which indicate missing locations.

strata

An optional character vector containing names of stratification variables. If supplied, these are added to the activity and location variables to be used for grouping. Default: none.

Value

The summarised time use survey data with 'most popular' location added and rows then filtered to include one line for each combination of strata and activity. If there are multiple locations matching the maximum proportion of time spent in each location by stratum and activity then the first location id will be chosen.

Examples

if (FALSE) { # \dontrun{
tus_dat <- get_tus_dat()
missing_ids <- c(-9, 0, 10, 90)
strata <- c("sex", "agegr4", "nssec5", "daytype")
get_most_popular_locn(tus_dat, "most_popular_locn", missing_ids, strata)
} # }