@@ -460,7 +460,7 @@ To look at this, we'll need a bit more data. I found a list of NYC zip codes by
460
460
461
461
``` {r get-nyc-zip-borough, echo = F, include = F, eval = F}
462
462
library(xml2)
463
- library(tidyverse )
463
+ library(readr )
464
464
page <- read_html("https://www.nycbynatives.com/nyc_info/new_york_city_zip_codes.php")
465
465
nyc_zip_borough <- data.frame(ZipCode = c(xml_find_all(page, ".//tr/td[1]"),
466
466
xml_find_all(page, ".//tr/td[4]")) %>%
@@ -471,15 +471,15 @@ nyc_zip_borough <- data.frame(ZipCode = c(xml_find_all(page, ".//tr/td[1]"),
471
471
purrr::map_chr(xml_text) %>%
472
472
stringr::str_trim()) %>%
473
473
unique()
474
- write_csv(nyc_zip_borough, "data/ nyc_zip_borough.csv")
474
+ write_csv(nyc_zip_borough, file = file.path("../", "data", " nyc_zip_borough.csv") )
475
475
```
476
476
477
477
::: panel-tabset
478
478
479
479
#### R {-}
480
480
481
481
``` {r merge-dog-borough-info}
482
- borough_zip <- read_csv("https://raw.githubusercontent.com/srvanderplas/unl-stat850 /main/data/nyc_zip_borough.csv")
482
+ borough_zip <- read_csv("https://raw.githubusercontent.com/srvanderplas/stat-computing-r-python /main/data/nyc_zip_borough.csv")
483
483
484
484
# Remove the Borough column from dogs
485
485
dogs <- dogs[, which(names(dogs) != "Borough")]
@@ -491,8 +491,7 @@ head(dogs)
491
491
#### Python {-}
492
492
493
493
``` {python merge-dog-borough-info-py}
494
- borough_zip = pd.read_csv("https://raw.githubusercontent.com/srvanderplas/unl-stat850/main/data/nyc_zip_borough.csv")
495
-
494
+ borough_zip = pd.read_csv("https://raw.githubusercontent.com/srvanderplas/stat-computing-r-python/main/data/nyc_zip_borough.csv")
496
495
dogs = dogs.drop('Borough', axis = 1) # drop borough column
497
496
dogs = pd.merge(dogs, borough_zip, on = 'ZipCode')
498
497
dogs.head()
0 commit comments