In this project, you will find the mean, median, and mode cost of one-bedroom apartments in three of the five New York City boroughs: Brooklyn, Manhattan, and Queens.
Using your findings, you will make conclusions about the cost of living in each of the boroughs. We will also discuss an important assumption that we make when we point out differences between the boroughs.
We worked with Streeteasy.com to collect this data. While we will only focus on the cost of one-bedroom apartments, the dataset includes a lot more information if you’re interested in asking your own questions about the Brooklyn, Manhattan, and Queens housing market.
1.We’ve imported data about one-bedroom apartments in three of New York City’s boroughs: Brooklyn, Manhattan, and Queens. We saved the values to:
1.brooklyn_one_bed
2.manhattan_one_bed
3.queens_one_bed
In this project, we only care about the price of apartments, so we saved the price of apartments in each borough to:
1.brooklyn_price
2.manhattan_price
3.queens_price
If you want to see what the data stored in these variables looks like, you can type the variable names in a code block. When you click run, the variables (and their contents) will appear.
# Load libraries
library(readr)
library(dplyr)
library(DescTools)
# Read in housing data
brooklyn_one_bed <- read_csv('brooklyn.csv')
brooklyn_price <- brooklyn_one_bed$rent
manhattan_one_bed <- read_csv('manhattan.csv')
manhattan_price <- manhattan_one_bed$rent
queens_one_bed <- read_csv('queens.csv')
queens_price <- queens_one_bed$rent
brooklyn_one_bed
manhattan_one_bed
queens_one_bed
brooklyn_price
[1] 3600 3900 2700 4900 3900 2750 2700 4905 2000 3200 2950 1950 1799 5317 2300 2400 3045 3790
[19] 2500 2600 3226 4995 6950 3500 3080 6992 6000 2700 4246 2299 2400 2485 4000 2995 1500 4370
[37] 2400 3200 3500 1600 1650 2600 2400 1800 2295 4700 1875 2900 3600 2450 3200 3300 8900 2195
[55] 2900 2400 2000 3100 1650 3090 4120 4079 1984 2745 1695 2850 2123 2250 4995 2600 5300 3786
[73] 5300 2900 2975 1500 4000 2200 6300 2400 2350 5145 2900 1400 2900 1995 2650 2300 5000 5195
[91] 3600 4850 3500 3800 2575 3000 2200 2428 1600 4488 4950 3495 1950 3500 2650 5050 2200 2150
[109] 15750 4215 2348 1581 2850 3171 3300 3225 3000 1675 2225 5800 1550 5346 3155 2400 2250 2500
[127] 1500 11000 3800 2395 2395 3200 4550 4615 2850 2800 3000 3900 2814 5299 1550 2200 6875 2978
[145] 5550 1400 3875 1650 4800 1750 3305 3300 4695 2200 3070 3445 2250 1775 4675 3795 5000 4695
[163] 3348 2395 2970 2840 3000 3461 2450 2599 2100 1950 3900 2300 2300 3000 2400 1350 3400 2150
[181] 2575 2995 6000 2850 1325 2650 4595 2799 2200 3800 4361 1900 3200 3300 2650 4299 2400 2640
[199] 2300 2400 2300 2950 2300 2600 3385 1800 4500 4595 2760 2530 2495 3495 3850 13500 4500 2500
[217] 3500 4195 9400 2550 5100 3369 2775 3029 4800 5295 2395 2995 5250 2975 4795 2450 4500 2650
[235] 4350 3100 3370 1832 6500 2780 3067 1600 2650 3375 2850 3994 3875 3600 3500 2615 2200 3120
[253] 3299 3000 4545 1400 3300 5995 1900 2630 1895 1895 4500 4095 3400 2775 2700 2925 2400 1900
[271] 1650 4145 2500 2300 3195 2750 1650 4500 3199 4300 2000 2534 2500 3750 3400 3225 4200 2488
[289] 2550 3250 3411 1500 1995 2510 3900 3600 3000 3320 3400 2495 6600 2000 2570 2900 2000 3204
[307] 6895 3499 3800 3700 3540 2704 1425 1950 1581 4500 2000 2500 3995 5320 2590 5500 4350 3950
[325] 2350 3415 2500 4650 3340 1700 2450 2100 7200 1950 2300 3725 3100 3300 2775 3600 2500 3600
[343] 3099 3995 2500 1900 2729 2500 2417 6250 2550 1700 2195 3805 2750 4000 3950 2446 3800 2635
[361] 2600 1800 1850 2500 2900 3337 2150 3000 4850 3295 3695 2200 3385 4395 4500 3000 4390 5000
[379] 2695 6100 3675 3000 3600 2800 2200 2835 2199 1750 3795 1425 9000 2200 3600 2200 6250 2600
[397] 3150 3195 4314 2800 3750 2910 2650 1800 3500 4600 4350 3092 1938 1995 4500 5500 3450 3950
[415] 2650 4000 2400 3000 4200 4000 5995 4950 2300 3000 6565 3100 3333 5250 2650 12000 10000 2200
[433] 2625 1550 2700 2500 4750 2150 2700 3875 2100 4400 2800 2650 2300 3630 4416 2000 2275 2999
[451] 2975 2854 2700 3750 3800 3600 4400 3400 3200 3400 2650 4350 6995 8900 3200 2500 1800 1600
[469] 4100 1800 2899 2400 1900 3475 4600 3000 2750 2700 2200 4899 3200 3300 5300 3150 5630 4349
[487] 1750 4500 2734 2000 2500 2550 2850 3570 2875 3256 3025 2699 1550 1975 1650 1800 2500 4100
[505] 4620 3250 2200 3800 3680 2965 2600 2750 1800 1475 2400 3325 2300 2856 2840 3199 3400 2999
[523] 2769 3500 4190 2999 2200 2750 3600 1900 1750 2100 4100 6320 3390 2300 2125 3784 6500 2000
[541] 2400 5039 3515 3100 4350 5405 3195 4700 2995 2350 4095 4350 3500 5100 2650 1575 1800 4583
[559] 5800 2149 1800 5200 2475 2999 1800 2875 4100 1825 3150 6250 3485 2300 3100 3025 2200 4033
[577] 1500 3595 2300 3210 4200 3999 1650 3671 2125 2625 2200 1675 2000 2450 2000 4245 3350 2550
[595] 1450 3000 1971 3434 3500 4200 2650 2500 5250 12000 2350 2550 3490 2891 2685 4200 2000 4500
[613] 2950 4354 3300 3695 5195 3595 3200 2995 2850 2075 1725 2200 1550 2750 2500 4050 3200 2800
[631] 2495 2665 4500 3825 3400 2745 9495 2550 2395 2300 4750 2500 3525 2600 3400 2215 5100 3300
[649] 2800 5210 2300 2600 4750 4303 5300 2050 4995 2350 3450 4250 2400 2735 2500 2750 3200 4075
[667] 2150 6500 3100 2995 2350 3450 4400 2250 2800 3299 4800 2250 3300 3400 2100 3349 3900 2800
[685] 3650 2891 3500 4200 2815 3896 2800 2750 2900 4100 2995 1650 3495 3950 4000 4995 3175 3414
[703] 3500 4250 2000 2850 2800 3000 1800 2800 2675 3100 3000 2300 2995 3758 9000 2600 2850 3100
[721] 4350 5250 2580 1675 2600 3450 2995 4024 4100 2850 4400 3400 2850 5995 5262 3950 16000 6600
[739] 2650 5600 3450 2699 3500 4300 2950 2400 2118 2900 3600 3300 2499 3600 2750 2500 2300 3337
[757] 2800 3050 2720 3595 2500 2940 2550 3675 3100 3450 5000 3117 2600 2800 3050 2200 11500 2680
[775] 3350 4500 3100 3099 4200 2474 8500 3650 1590 1675 3595 6426 2050 2150 2745 3500 5999 3300
[793] 2123 3500 2250 3680 2445 5699 5860 2450 1400 3170 3350 4650 1850 4495 3400 1500 5000 5295
[811] 4500 1900 1800 4100 2000 3465 2195 2650 1695 3700 4000 2850 3400 1850 7250 2891 4190 3300
[829] 1995 5100 2550 1275 3225 2600 3800 3295 3750 2600 2395 4500 3200 1695 4325 2400 1700 1846
[847] 2395 2700 3300 2251 4200 2675 4000 3029 2500 3138 3250 3700 5900 6650 2500 1450 1375 4300
[865] 4800 2100 1875 3099 3942 2765 2400 2400 3080 2500 1795 2395 4595 1795 3000 2585 3495 2695
[883] 3200 1875 3100 2930 4250 3100 1400 1650 3000 2383 2769 2764 2550 2658 4200 2800 1800 2735
[901] 2800 1850 3200 2975 1846 3850 4350 3050 4900 2600 3100 2850 2450 6850 2000 1550 2200 3500
[919] 4000 4600 4350 2999 2400 3000 1925 2400 2700 4395 2995 3295 2200 4395 3595 2700 2995 3700
[937] 5900 3550 3241 2600 2999 3250 4500 1995 2100 3895 1625 3000 1475 2700 4025 3850 4190 4200
[955] 2500 2480 2875 2150 3899 3500 2500 1850 3270 3100 3300 2635 4500 2250 3375 3350 3195 3184
[973] 3099 6923 4595 2300 2660 2100 3950 2250 3300 1850 4600 3000 3800 4700 1750 4150 2300 2300
[991] 1600 1850 4095 2750 16000 1900 4000 2850 1795 2580
[ reached 'max' / getOption("max.print") -- omitted 13 entries ]
manhattan_price
[1] 2550 11500 4500 4795 17500 3800 1995 2995 15000 4650 2950 6920 4875 4850 3700 4200 2195 4200
[19] 9000 4950 3000 2450 1950 3375 2395 4990 7495 10000 3090 10904 2100 2499 3650 3800 9800 4350
[37] 2495 3625 9000 5800 3295 2200 5485 2950 2750 8200 2000 4995 1875 3900 2400 5325 3500 3900
[55] 3375 6400 12500 2595 2199 2430 10000 6400 5895 2600 4700 6000 4995 3388 3483 2900 4600 1695
[73] 2700 11750 5080 4890 3800 5200 2800 6000 2100 2300 16750 6400 5595 2800 3219 8500 10000 3775
[91] 4350 3995 4995 7195 7600 2995 4490 3450 3800 14662 2575 3750 6695 5500 5475 4910 5150 4950
[109] 5225 13750 4500 2200 4000 4300 2750 5120 5895 11723 4270 2995 2150 3500 2150 2350 4499 3815
[127] 3200 1625 3500 3495 2025 2700 3550 6000 4750 2800 5000 3500 6800 2775 7900 3995 9950 3400
[145] 3300 11000 3250 5700 7246 5688 6350 2800 5740 3500 12500 2695 2895 16500 5000 6600 3490 4800
[163] 4050 5850 2300 3275 4095 2995 5900 3920 4795 3800 12500 5000 4365 3950 4000 3905 4000 2750
[181] 3631 2095 7995 2995 18450 4250 4995 4200 4300 14000 8250 3950 5995 4785 4800 3595 4500 5415
[199] 5500 3700 1700 2799 9300 4990 7795 6000 2450 7000 3250 5495 4050 3900 3195 3000 3700 7950
[217] 2995 2600 2095 5668 7995 3190 2300 4950 3100 6400 3950 4400 6450 3100 7700 18250 13500 5780
[235] 6800 3300 5500 1750 8500 2650 3700 6000 5145 2600 1600 3058 4475 4950 3932 3000 5150 3450
[253] 2250 4260 4375 10995 2900 4200 7500 3665 3800 2995 3935 2495 3400 5535 3600 5440 1950 4100
[271] 2200 7000 4695 5300 7900 3600 1950 7500 5150 4730 1460 5300 9995 3950 2685 2695 3500 4000
[289] 14000 9950 3675 7250 3425 2125 4200 2999 5100 5256 3688 2595 3850 4000 3290 2100 5200 10000
[307] 6300 4870 4500 6000 2500 14500 4000 2150 12000 2300 10780 1650 5350 4495 14500 3800 1800 2450
[325] 6000 2750 5050 2200 3085 3650 3800 3500 10500 7999 4185 3350 2850 3323 4300 5900 3200 10662
[343] 6650 3800 4080 5000 3500 7500 4575 4000 3925 5500 8500 3300 15000 4950 9995 3495 2600 3000
[361] 5855 4500 7995 18000 2450 3791 5600 3945 3000 7500 3950 3450 3200 5850 10995 2800 2575 1599
[379] 3400 2995 3790 4195 9415 1795 6000 4765 5250 17500 5250 3845 8000 3560 1775 5100 8000 7650
[397] 15000 3100 2445 5200 3285 10000 5250 4600 4450 9000 7000 15000 2995 4200 2600 9700 6058 11257
[415] 5000 2400 3250 14000 4035 3395 14000 2825 2050 2995 5050 5900 2450 2200 3730 5600 2800 11000
[433] 4350 3900 6500 7495 2999 2595 5250 5995 3946 7800 3200 4950 3650 2600 3100 4500 5250 3375
[451] 4600 3675 3350 3500 6250 4700 2485 12500 4615 3250 4000 2000 3950 2099 10000 3195 2750 2950
[469] 5400 5100 2150 4800 3415 5995 3695 2650 4600 2790 3700 4500 14500 3550 3535 9000 4000 3323
[487] 6495 2400 4600 8000 4495 2900 6080 5100 3453 9000 9350 3510 4506 4000 3000 3370 6310 4995
[505] 3495 3823 12500 12000 7995 3100 4610 4768 3650 2750 3900 4000 5500 1850 3150 2400 11500 2700
[523] 9950 3200 4495 3150 5500 3950 4200 3195 4000 9995 5125 2625 3225 5950 2650 7500 5200 6650
[541] 2450 6700 7195 3350 4686 4500 2600 3000 6950 4650 3350 6854 3800 8500 2950 6250 7350 4750
[559] 2720 2495 2150 2950 2700 3341 5300 3400 6900 2690 2000 3950 2600 15000 13900 2990 4795 2850
[577] 3500 6995 6500 2700 7500 5700 3900 4195 7290 3800 3410 2900 9250 13000 10000 4500 3000 2400
[595] 3000 6861 6917 3800 3800 9250 9995 5995 4280 4000 4275 3700 2395 9995 6000 2050 3000 4565
[613] 3800 2900 13500 1999 3100 9750 2500 11500 3900 5400 2425 5940 10495 3500 6055 11538 5900 4140
[631] 3876 2879 13000 5995 8250 3595 6500 18500 6350 5250 3300 3750 8000 5200 7795 3500 13000 3642
[649] 3100 3900 3500 7000 8095 7500 7995 3200 9000 3365 6465 2900 6700 3705 4216 3395 2735 2800
[667] 8100 2650 2900 5555 15900 3575 8750 5275 15000 7500 1895 4750 4600 3150 4050 7085 3595 3900
[685] 3595 5250 2495 12500 3645 7350 5110 2550 2900 4650 3800 3530 2795 5800 3500 2215 3325 4250
[703] 8500 2935 8995 6594 9850 8200 6776 5999 2095 2595 3500 3300 6800 16000 3750 3195 4700 2805
[721] 4150 3515 5850 3850 6350 4000 5250 3645 3725 2695 2650 1995 6500 3700 4500 3350 5999 2800
[739] 4350 2600 3800 2500 2800 2850 6118 5995 3850 5395 3750 1443 2795 4500 3600 3750 3800 12000
[757] 5155 2500 2250 3750 4995 4198 7500 3000 3093 11000 4195 2700 2499 3865 5935 4950 4600 8500
[775] 3350 3550 4600 4850 3150 3400 2200 3300 7000 3850 6500 12000 2975 3100 2990 6995 3229 3250
[793] 3254 8950 3495 4850 4995 2900 3184 3000 10400 2100 3160 3308 3500 4846 2300 2750 2695 6995
[811] 6000 2620 4895 3250 3498 1990 2650 5795 7500 2600 6725 3200 20000 3640 4500 5600 3900 3285
[829] 2850 3950 2775 3840 2100 2295 3700 3550 8500 5500 5345 5150 3965 4400 5340 2100 7250 2850
[847] 1987 3600 3300 3795 2400 4410 9250 3230 3500 4000 3813 3750 4590 4056 7250 3595 8500 2950
[865] 3600 3730 3100 3495 3700 3850 3600 2095 7650 2790 3295 3000 8900 2960 4400 2995 1950 3850
[883] 4000 5819 4100 4195 4200 3825 5250 3400 2723 3800 15000 3800 3342 7880 4965 16000 1600 3187
[901] 2750 5958 4100 3600 3700 2700 4000 3300 2350 3795 7500 5771 4600 3400 3715 2750 1600 6500
[919] 1500 2795 3211 6900 2450 4400 3895 5260 7500 5495 2595 5500 5000 4150 3100 3995 3875 7000
[937] 3775 10500 12000 2750 6800 3700 3167 3775 3495 2900 3805 5950 8500 6806 3195 10600 3300 2950
[955] 2995 5300 4400 3100 3990 2499 4695 7100 5600 2400 4195 5450 3300 3405 12000 5800 7995 1700
[973] 3900 2595 3465 2550 3500 6300 4500 3395 14000 6900 3505 2975 2100 9000 8500 5995 3700 6000
[991] 16000 2050 3150 5018 5900 3025 3600 4585 3500 2500
[ reached 'max' / getOption("max.print") -- omitted 2539 entries ]
queens_price
[1] 3000 1950 3500 1725 1700 2550 2550 3100 1399 2275 3400 2695 4275 2000 2200 2400 1850 1600 2025 1900 2200
[22] 2000 3295 2350 3450 1450 1975 2995 2900 2000 1495 3400 3000 2535 2945 1900 2450 1700 1995 1800 1600 1835
[43] 1625 3450 1625 3275 2500 3410 1650 2050 1850 2295 1700 2595 2695 1550 2550 3300 2955 1575 3795 2550 2750
[64] 2825 2995 2550 2650 2395 1741 4850 1950 2650 1950 2150 3500 1465 2300 2100 3700 2870 2395 4199 3200 2395
[85] 1700 5700 4100 1600 4475 3500 1900 2495 2350 2000 2700 2300 1550 2950 1250 3500 2550 4450 5575 2795 1825
[106] 2225 2950 1590 2050 2800 2600 2700 4085 2200 2498 2650 1450 3325 1500 2750 2745 3911 2535 2250 1350 2907
[127] 2550 1950 2800 3400 2400 1400 1725 2800 1700 2275 2600 2500 2000 3800 3160 2650 1750 2000 1750 1750 1995
[148] 1550 3300 2200 2535 2300 3139 1950 1925 1650 2350 2600 1800 1475 3300 2200 1475 3495 3000 2200 3200 1850
[169] 2800 2650 2350 1650 1600 1650 1500 3950 1625 1800 2175 3350 2950 2499 1800 3125 5350 2550 1350 2450 4500
[190] 1450 3911 1900 1350 2850 2600 1550 2750 2200 3300 3300 2200 2725 2900 2550 2700 2200 2100 1925 3975 2195
[211] 3200 2250 3400 3200 2600 2700 3150 2325 1999 2900 1750 3117 1695 1799 1725 3475 1500 1900 2200 1450 2895
[232] 3350 2625 3225 2400 2380 1605 2200 1585 3750 1750 2000 3000 2950 1750 3250 1900 2600 2200 2800 3600 1975
[253] 2250 2295 1725 3000 1850 2575 8000 2175 2950 2485 1575 2100 3175 2050 1725 2095 2300 3193 3575 2900 1625
[274] 2795 1825 1700 2450 1750 2650 2000 3000 1750 2575 2200 3450 1750 2100 2569 2200 3125 1399 2750 1450 4700
[295] 1625 1950 2350 1850 1850 1900 2350 2000 2500 2050 1650 1750 2400 3125 1625 3964 4000 2350 2000 1600 2275
[316] 2100 2095 1950 2250 1895 2000 1975 1700 2000 1299 3300 3125 2650 2050 2700 1971 2995 1825 3325 2250 2300
[337] 2700 1250 2950 2995 1950 1700 3300 3500 2570 2595 2400 2600 3225 3700 3175 4150 2550 3400 6400 2500 1585
[358] 2600 2450 5057 2100 1875 2650 2700 1299 1800 2250 4707 1800 2000 2250 3110 2300 2950 1625 3300 2800 3095
[379] 1950 2100 2300 2125 2895 1975 2375 1695 2400 2299 1950 2975 2600 2000 3950 1650 1995 1550 1900 2150 2200
[400] 3500 3275 2600 2500 1750 2700 1585 1425 3229 2800 2545 2550 4750 2000 1999 1895 1650 2050 4350 1345 5125
[421] 2900 1895 3700 1845 3000 1800 1800 3300 1950 3700 2350 1795 1875 3050 2625 1600 2950 5300 3500 2350 4850
[442] 2650 2200 3750 2950 2200 2250 2650
2.Find the average value of one-bedroom apartments in Brooklyn and save the value to brooklyn_mean.
#Calculate Mean
brooklyn_mean <- mean(brooklyn_price)
brooklyn_mean
[1] 3327.404
3.Find the average value of one-bedroom apartments in Manhattan and save the value to manhattan_mean.
#Calculate Mean
manhattan_mean <- mean(manhattan_price)
manhattan_mean
[1] 5138.94
4.Find the average value of one-bedroom apartments in Queens and save the value to queens_mean.
#Calculate Mean
queens_mean <- mean(queens_price)
queens_mean
[1] 2516.147
5.Find the median value of one-bedroom apartments in Brooklyn and save the value to brooklyn_median.
#Calculate Median
brooklyn_median <- median(brooklyn_price)
brooklyn_median
[1] 3000
6.Find the median value of one-bedroom apartments in Manhattan and save the value to manhattan_median.
manhattan_median <- median(manhattan_price)
manhattan_median
[1] 4000
7.Find the median value of one-bedroom apartments in Queens and save the value to queens_median.
#Calculate Median
queens_median <- median(queens_price)
queens_median
[1] 2350
8.Find the mode value of one-bedroom apartments in Brooklyn and save the value to brooklyn_mode.
#Calculate Mode
brooklyn_mode <- Mode(brooklyn_price)
brooklyn_mode
[1] 2500
attr(,"freq")
[1] 26
9.Find the mode value of one-bedroom apartments in Manhattan and save the value to manhattan_mode.
#Calculate Mode
manhattan_mode <- Mode(manhattan_price)
manhattan_mode
[1] 3500
attr(,"freq")
[1] 77
10.Find the mode value of one-bedroom apartments in Queens and save the value to queens_mode.
#Calculate Mode
queens_mode <- Mode(queens_price)
queens_mode
[1] 2200
attr(,"freq")
[1] 17
11.Now what?
We don’t find the mean, median, and mode of a dataset for the sake of it.
The point is to make inferences from our data. What can you say about the housing prices in Brooklyn, Queens, and Manhattan? Besides, “It’s really expensive to live in any of them.”
Take a minute to think through it. We added our thoughts to the hint.
*Hint
It looks like the average cost of one-bedroom apartments in Manhattan is the most, and in Queens is the least. This pattern holds for the median and mode values as well.
While the mode is not the most important indicator of centrality, the fact that mean, median, and mode are within a few hundred dollars for each borough indicates the data is centered around:
1.$3,300 for Brooklyn
2.$3,900 for Manhattan
3.$2,300 for Queens
12.Did you make any assumptions when you drew inferences in the previous task?
If so, what assumptions did you make? We added our thoughts to the hint.
*Hint
We assumed that the data from Streeteasy is representative of housing prices for the entire borough. Given that Streeteasy is only used by a subset of property owners, this is not a fair assumption. A quick search on rentcafe.com will tell you the averages are more like:
1.$2,695 for Brooklyn one-bedroom apartments
2.$4,188 for Manhattan one-bedroom apartments
3.$2,178 for Queens one-bedroom apartments
This is an interesting finding. Why may the cost from rentcafe.com be higher in Manhattan than in Brooklyn or Queens?
Although we don’t have the answer to this question, it’s worth thinking about the possible differences between our Streeteasy data and where rentcafe is pulling their data.
13.Finally, think about what the histogram for each dataset will look like.
If you have the time, take a minute to make a rough sketch of the histograms for the cost of a one-bedroom apartment in Brooklyn, Manhattan, and Queens.
You can see someone else’s attempt at a sketch of the Brooklyn histogram.
knitr::include_graphics("C:/Users/kuoan/Desktop/R Code/His1.png")
library(ggplot2)
#plot data
hist <- qplot(brooklyn_one_bed$rent,
geom='histogram',
binwidth = 500,
main = 'Brooklyn 1 bedroom price',
xlab = 'Cost',
ylab = 'Count',
fill=I("blue"),
col=I("black"),
alpha=I(.2)) +
geom_vline(aes(xintercept=median(brooklyn_one_bed$rent),
color="median"), linetype="dashed",
size=1) +
geom_vline(aes(xintercept=mean(brooklyn_one_bed$rent),
color="mean"), linetype="solid",
size=1) +
geom_vline(aes(xintercept=Mode(brooklyn_one_bed$rent),
color="mode"), linetype="solid",
size=1) +
scale_color_manual(name = "statistics", values = c(median = "blue", mean = "red", mode="green"))
hist
#plot data
hist <- qplot(manhattan_one_bed$rent,
geom='histogram',
binwidth = 500,
main = 'Manhattan 1 bedroom price',
xlab = 'Cost',
ylab = 'Count',
fill=I("blue"),
col=I("black"),
alpha=I(.2)) +
geom_vline(aes(xintercept=median(manhattan_one_bed$rent),
color="median"), linetype="dashed",
size=1) +
geom_vline(aes(xintercept=mean(manhattan_one_bed$rent),
color="mean"), linetype="solid",
size=1) +
geom_vline(aes(xintercept=Mode(manhattan_one_bed$rent),
color="mode"), linetype="solid",
size=1) +
scale_color_manual(name = "statistics", values = c(median = "blue", mean = "red", mode="green"))
hist
#plot data
hist <- qplot(queens_one_bed$rent,
geom='histogram',
binwidth = 500,
main = 'Queens 1 bedroom price',
xlab = 'Cost',
ylab = 'Count',
fill=I("blue"),
col=I("black"),
alpha=I(.2)) +
geom_vline(aes(xintercept=median(queens_one_bed$rent),
color="median"), linetype="dashed",
size=1) +
geom_vline(aes(xintercept=mean(queens_one_bed$rent),
color="mean"), linetype="solid",
size=1) +
geom_vline(aes(xintercept=Mode(queens_one_bed$rent),
color="mode"), linetype="solid",
size=1) +
scale_color_manual(name = "statistics", values = c(median = "blue", mean = "red", mode="green"))
hist
# Don't look below here
# Mean
if(exists('brooklyn_mean')) {
print(paste("The mean price in Brooklyn is" , round(brooklyn_mean, digits=2)))
}else{
print("The mean price in Brooklyn is not yet defined.")
}
[1] "The mean price in Brooklyn is 3327.4"
if(exists("manhattan_mean")) {
print(paste("The mean price in Manhattan is", round(manhattan_mean,digits=2)))
} else {
print("The mean in Manhattan is not yet defined.")
}
[1] "The mean price in Manhattan is 5138.94"
if(exists("queens_mean")) {
print(paste("The mean price in Queens is" , round(queens_mean,digits=2)))
} else {
print("The mean price in Queens is not yet defined.")
}
[1] "The mean price in Queens is 2516.15"
# Median
if(exists("brooklyn_median")) {
print(paste("The median price in Brooklyn is" , brooklyn_median))
}else{
print("The median price in Brooklyn is not yet defined.")
}
[1] "The median price in Brooklyn is 3000"
if(exists("manhattan_median")) {
print(paste("The median price in Manhattan is", manhattan_median))
} else {
print("The median in Manhattan is not yet defined.")
}
[1] "The median price in Manhattan is 4000"
if(exists("queens_median")) {
print(paste("The median price in Queens is" , queens_median))
} else {
print("The median price in Queens is not yet defined.")
}
[1] "The median price in Queens is 2350"
#Mode
if(exists("brooklyn_mode")) {
print(paste("The mode price in Brooklyn is" , brooklyn_mode))
}else{
print("The mode price in Brooklyn is not yet defined.")
}
[1] "The mode price in Brooklyn is 2500"
if(exists("manhattan_median")) {
print(paste("The mode price in Manhattan is", manhattan_mode))
} else {
print("The mode in Manhattan is not yet defined.")
}
[1] "The mode price in Manhattan is 3500"
if(exists("queens_median")) {
print(paste("The mode price in Queens is" , queens_mode))
} else {
print("The mode price in Queens is not yet defined.")
}
[1] "The mode price in Queens is 2200"