Tidyverse activity 1: Hotels

Getting Started

  1. Navigate to your CMSC 121 RStudio project

  2. Create a new Quarto Document for this in-class activity called tidyverse_in_class_activity_1.qmd

  3. Load the tidyverse package

  4. In the console, run the command glimpse(hotels) and peruse the information it generates about the data frame.

Exercises

Question 1

Are people traveling on a whim? Let’s see…

Copy the code below into your file, fill in the blanks so that it will filter for hotel bookings where the guest is not from the US (country code “USA”) and the lead_time is less than 1 day.

hotels %>% 
  filter(
    country ____ "USA",
    lead_time ____ ____
  )

Question 2

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

Copy the below code chunk into your Quarto and replace:

  • [AT LEAST] with the logical operator for “at least” (in two places)

  • [OR] with the logical operator for “or”

hotels %>%
  filter(
    children [AT LEAST] 1 [OR] babies [AT LEAST] 1
    )

Question 3

Do you think it’s more likely to find bookings with children or babies in city hotels or resort hotels? Test your intuition. Using filter(), determine the number of bookings in resort hotels that have more than 1 child OR baby in the room. Then, do the same for city hotels, and compare the numbers of rows in the resulting filtered data frames. In addition to your code, put your conclusion in a comment in the file.