library(readr)
airbnb <- read_csv("airbnb.csv")
## Rows: 48895 Columns: 16
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (5): name, host_name, neighbourhood_group, neighbourhood, room_type
## dbl  (10): id, host_id, latitude, longitude, price, minimum_nights, number_o...
## date  (1): last_review
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(airbnb)

Exercise I

MEAN FUNCTION FOR REVIEWS

mean_number_of_reviews <- function(airbnb) {
  mean_reviews <- mean(airbnb$number_of_reviews)
  return(mean_reviews)
}
mean_reviews <- mean_number_of_reviews(airbnb)
print(mean_reviews)
## [1] 23.27447

MEAN FUNCTION FOR PRICE

mean_price <- function(airbnb) {
  mean_price <- mean(airbnb$price)
  return(mean_price)
}

mean_price <- mean_price(airbnb)
print(mean_price)
## [1] 152.7207

Let’s validate the results with decribe function, but first, mark psych package.

library(psych)
describe(airbnb)
## Warning in FUN(newX[, i], ...): ningún argumento finito para min; retornando
## Inf
## Warning in FUN(newX[, i], ...): ningun argumento finito para max; retornando
## -Inf
##                                vars     n        mean          sd      median
## id                                1 48895 19017143.24 10983108.39 19677284.00
## name*                             2 48879    23963.73    13811.31    23928.00
## host_id                           3 48895 67620010.65 78610967.03 30793816.00
## host_name*                        4 48874     5428.50     3228.86     5315.00
## neighbourhood_group*              5 48895        2.68        0.74        3.00
## neighbourhood*                    6 48895      108.11       68.74       95.00
## latitude                          7 48895       40.73        0.05       40.72
## longitude                         8 48895      -73.95        0.05      -73.96
## room_type*                        9 48895        1.50        0.55        1.00
## price                            10 48895      152.72      240.15      106.00
## minimum_nights                   11 48895        7.03       20.51        3.00
## number_of_reviews                12 48895       23.27       44.55        5.00
## last_review                      13 38843         NaN          NA          NA
## reviews_per_month                14 38843        1.37        1.68        0.72
## calculated_host_listings_count   15 48895        7.14       32.95        1.00
## availability_365                 16 48895      112.78      131.62       45.00
##                                    trimmed         mad     min          max
## id                             19188061.30 14689959.59 2539.00  36487245.00
## name*                             23962.96    17712.62    1.00     47894.00
## host_id                        54170438.55 40836605.41 2438.00 274321313.00
## host_name*                         5399.50     4194.28    1.00     11452.00
## neighbourhood_group*                  2.61        1.48    1.00         5.00
## neighbourhood*                      106.81       88.96    1.00       221.00
## latitude                             40.73        0.05   40.50        40.91
## longitude                           -73.96        0.04  -74.24       -73.71
## room_type*                            1.48        0.00    1.00         3.00
## price                               121.43       68.20    0.00     10000.00
## minimum_nights                        3.58        2.97    1.00      1250.00
## number_of_reviews                    12.45        7.41    0.00       629.00
## last_review                            NaN          NA     Inf         -Inf
## reviews_per_month                     1.06        0.92    0.01        58.50
## calculated_host_listings_count        1.50        0.00    1.00       327.00
## availability_365                     96.50       66.72    0.00       365.00
##                                       range  skew kurtosis        se
## id                              36484706.00 -0.09    -1.23  49669.87
## name*                              47893.00  0.00    -1.20     62.47
## host_id                        274318875.00  1.21     0.17 355509.26
## host_name*                         11451.00  0.06    -1.16     14.61
## neighbourhood_group*                   4.00  0.37    -0.11      0.00
## neighbourhood*                       220.00  0.26    -1.26      0.31
## latitude                               0.41  0.24     0.15      0.00
## longitude                              0.53  1.28     5.02      0.00
## room_type*                             2.00  0.42    -0.97      0.00
## price                              10000.00 19.12   585.59      1.09
## minimum_nights                      1249.00 21.83   853.95      0.09
## number_of_reviews                    629.00  3.69    19.53      0.20
## last_review                            -Inf    NA       NA        NA
## reviews_per_month                     58.49  3.13    42.49      0.01
## calculated_host_listings_count       326.00  7.93    67.54      0.15
## availability_365                     365.00  0.76    -1.00      0.60

Validated