R/tidy_exhplaces.R

#' Prepare exhibition places data frame for analysis
#'
#' @param .df.list a dataset as exported by \code{\link{loaddata}}
#'
#' @return a data frame containing the exhibition places
#' @export
#'
#' @examples
#' exhplaces <- tidy_exhplaces(df.list)
tidy_exhplaces <- function(.df.list, .exhibitions){

  # get date of exhibitions per exhibition place
  first_last_exh <- .exhibitions %>%
    group_by(exh_place_id) %>%
    summarise(first_exh_yr = min(exh_start_Y),
              last_exh_yr = max(exh_start_Y))

  # get number of exhibitions for each exhibition place
  number_of_exhibitions <- exhibitions %>%
    group_by(exh_place_id) %>%
    summarise(num_of_exh = n_distinct(id))


  # get geocodes
  geocodes_exhplaces <- df.list[["geocodes_exhplaces"]] %>%
    select(id, country, countrycode, continent, lon, lat, loctype, address)


  exhplaces <- df.list[["exhplaces"]] %>%
    # exclude irrelevant data gathered from website
    select(- contains("top"),
           - contains("_linked"),
           - contains("_num"),
           - type,
           - begin_records,
           - end_records) %>%
    mutate(id = as.integer(id),
           type_exhplace = type_exhplace %>% str_replace("Non-Profit", "NonProfit")) %>%

    # join general information from available data
    left_join(first_last_exh, by = c("id" = "exh_place_id")) %>%
    left_join(number_of_exhibitions, by = c("id" = "exh_place_id")) %>%
    left_join(geocodes_exhplaces, by = "id")



  return(exhplaces)

}
Framus94/HierarchiesAndCareers documentation built on June 5, 2019, 8:52 a.m.