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 listingprice: nightly listing price in USDnbhood_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 listingdescription: listing descriptionroom_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 listinghost_name: name of listing hostlast_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)
# Begin coding here ...
airbnbprice <- read.csv("data/airbnb_price.csv")
airbnbroom <- read_excel("data/airbnb_room_type.xlsx")
airbnbreview <- read_tsv("data/airbnb_last_review.tsv", show_col_types = FALSE)# Merge the datasets on the common column 'listing_id'
merged_data <- airbnbprice %>%
inner_join(airbnbroom, by = "listing_id") %>%
inner_join(airbnbreview, by = "listing_id")
# Display the first few rows of the merged dataset
head(merged_data)# Convert the 'last_review' column to a date format
review_dates <- merged_data %>%
mutate(last_review_date = as.Date(last_review, format = "%B %d %Y")) %>%
summarize(first_reviewed = min(last_review_date),
last_reviewed = max(last_review_date))
# Display the structure of the dataset to confirm the change
str(review_dates)# Assuming 'merged_data' is the data frame we want to summarize
library(dplyr)
# Summarize the 'last_review' column
private_room_count <- merged_data %>%
mutate(room_type = str_to_lower(room_type)) %>%
#Count the number of each room_type
count(room_type) %>%
#Get row containing count for private rooms only
filter(room_type == "private room")
#Extract number of rooms
nb_private_rooms <- private_room_count$n
# What is the average listing price?
# To convert price to numeric, remove "dollars" from each value
avg_price <- merged_data %>%
mutate(price_clean = str_remove(price, " dollars") %>%
as.numeric()) %>%
# Take the mean of price_clean
summarize(avg_price = mean(price_clean)) %>%
# Convert from a tibble to a single number
as.numeric()
# Load solution values into solution tibble:
# Note first_reviewed and last_reviewed columns in
# review_dates were created earlier
review_dates$nb_private_rooms = nb_private_rooms
review_dates$avg_price = round(avg_price, 2)
print(review_dates)