Skip to content

Welcome to New York City, one of the most-visited cities in the world. There are many Airbnb listings in New York City to meet the high demand for temporary lodging for travelers, which can be anywhere between a few nights to many months. In this project, you will take a closer look at the New York Airbnb market by combining data from multiple file types like .csv, .tsv, and .xlsx (Excel files).

Recall that CSV, TSV, and Excel files are three common formats for storing data. Three files containing data on 2019 Airbnb listings are available to you:

data/airbnb_price.csv This is a CSV file containing data on Airbnb listing prices and locations.

  • listing_id: unique identifier of listing
  • price: nightly listing price in USD
  • nbhood_full: name of borough and neighborhood where listing is located

data/airbnb_room_type.xlsx This is an Excel file containing data on Airbnb listing descriptions and room types.

  • listing_id: unique identifier of listing
  • description: listing description
  • room_type: Airbnb has three types of rooms: shared rooms, private rooms, and entire homes/apartments

data/airbnb_last_review.tsv This is a TSV file containing data on Airbnb host names and review dates.

  • listing_id: unique identifier of listing
  • host_name: name of listing host
  • last_review: date when the listing was last reviewed
# We've loaded the necessary packages for you in the first cell. Please feel free to add as many cells as you like!
suppressMessages(library(dplyr)) # This line is required to check your answer correctly
options(readr.show_types = FALSE) # This line is required to check your answer correctly
library(readr)
library(readxl)
library(stringr)

# load data using read_...
airbnb_price <- read_csv("data/airbnb_price.csv", show_col_types = FALSE)
airbnb_room <- read_xlsx("data/airbnb_room_type.xlsx")
airbnb_review <- read_tsv("data/airbnb_last_review.tsv", show_col_types = FALSE)

# merge dataset into a single data
airbnb_merged <- airbnb_price %>%
	inner_join(airbnb_room, by = "listing_id") %>%
	inner_join(airbnb_review, by = "listing_id")
head(airbnb_merged)

# convert last_review as valid date format and summarize
airbnb_merged <- airbnb_merged %>%
	mutate(last_review = as.Date(last_review, format = "%B %d %Y"))
first_reviewed <- airbnb_merged %>%
	summarize(first_reviewed = min(last_review))
last_reviewed <- airbnb_merged %>%
	summarize(last_reviewed = max(last_review))

# fix cases in room_type to all lower case
airbnb_merged <- airbnb_merged %>%
	mutate(room_type = str_to_lower(room_type)) 

# find counts for private room
nb_private_rooms <- airbnb_merged %>%
	filter(room_type == "private room") %>%
	summarize(nb_private_rooms = n())
nb_private_rooms

# convert price column to numeric and find average
airbnb_merged <- airbnb_merged %>%
	mutate(price = as.numeric(str_remove(price, "dollars")))
avg_price <- airbnb_merged %>%
	summarize(avg_price = round(mean(price), 2))
avg_price

# create tibble of first and last review dates, count of private rooms, and avg price
library(tibble)
review_dates <- tibble(first_reviewed, last_reviewed, nb_private_rooms, avg_price)
review_dates