library(scales)
# Identify numeric variables for scaling
numeric_variables <- c("price", "minimum_nights", "number_of_reviews",
"reviews_per_month",
"calculated_host_listings_count",
"availability_365", "number_of_reviews_ltm")
# Perform Min-Max scaling for each numeric variable
scaled_data <- airbnb_data
scaled_data[, numeric_variables] <- lapply(airbnb_data[, numeric_variables],
rescale)
# Display the first few rows of the scaled dataset
head(scaled_data)
## id
## 1 4952
## 2 11464
## 3 21373
## 4 62799
## 5 75284
## 6 106365
## name
## 1 Place to stay in Palo Alto · ★4.81 · 1 bedroom · 1 bed · 2 shared baths
## 2 Rental unit in Santa Clara · ★4.50 · Studio · 1 bed · 1 bath
## 3 Place to stay in Palo Alto · ★4.87 · 1 bedroom · 1 bed · 2 shared baths
## 4 Place to stay in Palo Alto · ★4.89 · 1 bedroom · 3 beds · 2 shared baths
## 5 Place to stay in Palo Alto · ★4.87 · 1 bedroom · 1 bed · 2 shared baths
## 6 Guesthouse in Cupertino · ★4.93 · 1 bedroom · 1 bed · 1 bath
## host_id host_name neighbourhood_group neighbourhood latitude longitude
## 1 7054 1127 NA Palo Alto 37.43932 -122.1574
## 2 42458 493 NA Santa Clara 37.34415 -121.9870
## 3 7054 1127 NA Palo Alto 37.43972 -122.1553
## 4 7054 1127 NA Palo Alto 37.43934 -122.1572
## 5 7054 1127 NA Palo Alto 37.43923 -122.1574
## 6 551319 812 NA Cupertino 37.32194 -122.0051
## price minimum_nights number_of_reviews last_review reviews_per_month
## 1 0.001375378 0.016483516 0.09847597 2023-10-28 0.03408267
## 2 0.002100578 0.005494505 0.02344666 2023-08-05 0.01160261
## 3 0.001425392 0.016483516 0.31184056 2023-09-16 0.11602611
## 4 0.001825502 0.016483516 0.18405627 2023-12-16 0.09717186
## 5 0.001500413 0.016483516 0.25087925 2023-12-11 0.10007252
## 6 0.006976919 0.079670330 0.21922626 2023-08-12 0.08919507
## calculated_host_listings_count availability_365 number_of_reviews_ltm license
## 1 0.008097166 0.6931507 0.04268293
## 2 0.024291498 0.4164384 0.02439024
## 3 0.008097166 0.8219178 0.03048780
## 4 0.008097166 0.8465753 0.03658537
## 5 0.008097166 0.8273973 0.03658537
## 6 0.000000000 1.0000000 0.01219512 Exempt
## beds star_rating
## 1 1 4.81
## 2 1 4.50
## 3 1 4.87
## 4 3 4.89
## 5 1 4.87
## 6 1 4.93