---
title: "Lab 8.1 - Hotel Cleansing"
author: "Author Goes Here"
date: "Semester Goes Here"
output:
  html_document:
    code_download: true
---

```{r include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message = FALSE, warning = FALSE}
library(tidyverse)
library(skimr)
```

For this lab, do the following tasks on the [hotels dataset](https://cs.calvin.edu/courses/info/601/08programming/lab/data/hotels.csv) (see the full data dictionary below).

## Analysis

1. Check out the hotels dataset (again), this time using `skim()`.


2. Are people traveling on a whim (i.e., are they travelling on short lead times)?


3. How many bookings involve at least 1 child **or** baby?


4. Do you think it's more likely to find bookings with children or babies in city hotels or resort hotels?


5. Create a frequency table of the number of `adults` in a booking.


6. Create a frequency table of the number of canceled bookings.


7. Calculate minimum, mean, median, and maximum average daily rate (`adr`) grouped by `hotel` type so that you can get these statistics separately for resort and city hotels.


8. Explain two unusual values in the summary statistics above: a negative minimum; and a very high maximum. 


9. Plot the average ADR for each arrival month, separated by city vs resort hotel type. Here's a rather unimpressive example:

![average adr](https://cs.calvin.edu/courses/info/601/08programming/lab/images/lab81-adrs.png)

10. As a final practice exercise, unrelated to the analysis above, write a function that receives three numbers as arguments and returns the average of those three numbers. Then, write a code segment that calls that function to compute the average of the numbers 1, 2, and 3 (the return value should be 2).


## Data dictionary

Below is the full data dictionary.
Note that it is long (there are lots of variables in the data), but we will be using a limited set of the variables for our analysis.

| variable                       | class     | description                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:-------------------------------|:----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| hotel                          | character | Hotel (H1 = Resort Hotel or H2 = City Hotel)                                                                                                                                                                                                                                                                                                                                                                                        |
| is_canceled                    | double    | Value indicating if the booking was canceled (1) or not (0)                                                                                                                                                                                                                                                                                                                                                                         |
| lead_time                      | double    | Number of days that elapsed between the entering date of the booking into the PMS and the arrival date                                                                                                                                                                                                                                                                                                                              |
| arrival_date_year              | double    | Year of arrival date                                                                                                                                                                                                                                                                                                                                                                                                                |
| arrival_date_month             | character | Month of arrival date                                                                                                                                                                                                                                                                                                                                                                                                               |
| arrival_date_week_number       | double    | Week number of year for arrival date                                                                                                                                                                                                                                                                                                                                                                                                |
| arrival_date_day_of_month      | double    | Day of arrival date                                                                                                                                                                                                                                                                                                                                                                                                                 |
| stays_in_weekend_nights        | double    | Number of weekend nights (Saturday or Sunday) the guest stayed or booked to stay at the hotel                                                                                                                                                                                                                                                                                                                                       |
| stays_in_week_nights           | double    | Number of week nights (Monday to Friday) the guest stayed or booked to stay at the hotel                                                                                                                                                                                                                                                                                                                                            |
| adults                         | double    | Number of adults                                                                                                                                                                                                                                                                                                                                                                                                                    |
| children                       | double    | Number of children                                                                                                                                                                                                                                                                                                                                                                                                                  |
| babies                         | double    | Number of babies                                                                                                                                                                                                                                                                                                                                                                                                                    |
| meal                           | character | Type of meal booked. Categories are presented in standard hospitality meal packages: <br> Undefined/SC – no meal package;<br>BB – Bed & Breakfast; <br> HB – Half board (breakfast and one other meal – usually dinner); <br> FB – Full board (breakfast, lunch and dinner)                                                                                                                                                         |
| country                        | character | Country of origin. Categories are represented in the ISO 3155–3:2013 format                                                                                                                                                                                                                                                                                                                                                         |
| market_segment                 | character | Market segment designation. In categories, the term "TA" means "Travel Agents" and "TO" means "Tour Operators"                                                                                                                                                                                                                                                                                                                      |
| distribution_channel           | character | Booking distribution channel. The term "TA" means "Travel Agents" and "TO" means "Tour Operators"                                                                                                                                                                                                                                                                                                                                   |
| is_repeated_guest              | double    | Value indicating if the booking name was from a repeated guest (1) or not (0)                                                                                                                                                                                                                                                                                                                                                       |
| previous_cancellations         | double    | Number of previous bookings that were cancelled by the customer prior to the current booking                                                                                                                                                                                                                                                                                                                                        |
| previous_bookings_not_canceled | double    | Number of previous bookings not cancelled by the customer prior to the current booking                                                                                                                                                                                                                                                                                                                                              |
| reserved_room_type             | character | Code of room type reserved. Code is presented instead of designation for anonymity reasons                                                                                                                                                                                                                                                                                                                                          |
| assigned_room_type             | character | Code for the type of room assigned to the booking. Sometimes the assigned room type differs from the reserved room type due to hotel operation reasons (e.g. overbooking) or by customer request. Code is presented instead of designation for anonymity reasons                                                                                                                                                                    |
| booking_changes                | double    | Number of changes/amendments made to the booking from the moment the booking was entered on the PMS until the moment of check-in or cancellation                                                                                                                                                                                                                                                                                    |
| deposit_type                   | character | Indication on if the customer made a deposit to guarantee the booking. This variable can assume three categories:<br>No Deposit – no deposit was made;<br>Non Refund – a deposit was made in the value of the total stay cost;<br>Refundable – a deposit was made with a value under the total cost of stay.                                                                                                                        |
| agent                          | character | ID of the travel agency that made the booking                                                                                                                                                                                                                                                                                                                                                                                       |
| company                        | character | ID of the company/entity that made the booking or responsible for paying the booking. ID is presented instead of designation for anonymity reasons                                                                                                                                                                                                                                                                                  |
| days_in_waiting_list           | double    | Number of days the booking was in the waiting list before it was confirmed to the customer                                                                                                                                                                                                                                                                                                                                          |
| customer_type                  | character | Type of booking, assuming one of four categories:<br>Contract - when the booking has an allotment or other type of contract associated to it;<br>Group – when the booking is associated to a group;<br>Transient – when the booking is not part of a group or contract, and is not associated to other transient booking;<br>Transient-party – when the booking is transient, but is associated to at least other transient booking |
| adr                            | double    | Average Daily Rate as defined by dividing the sum of all lodging transactions by the total number of staying nights                                                                                                                                                                                                                                                                                                                 |
| required_car_parking_spaces    | double    | Number of car parking spaces required by the customer                                                                                                                                                                                                                                                                                                                                                                               |
| total_of_special_requests      | double    | Number of special requests made by the customer (e.g. twin bed or high floor)                                                                                                                                                                                                                                                                                                                                                       |
| reservation_status             | character | Reservation last status, assuming one of three categories:<br>Canceled – booking was canceled by the customer;<br>Check-Out – customer has checked in but already departed;<br>No-Show – customer did not check-in and did inform the hotel of the reason why                                                                                                                                                                       |
| reservation_status_date        | double    | Date at which the last status was set. This variable can be used in conjunction with the Reservation Status to understand when was the booking canceled or when did the customer checked-out of the hotel                                                                                                                             |
