取得並設定你的 Census API 金鑰
tidycensus 是一個 R 套件,可將美國 Census Bureau 的資料以適合在 Tidyverse 中使用的格式取回。
若要用 tidycensus R 套件從美國 Census Bureau 取得資料,你需要先申請並設定一組「Census API 金鑰」。取得金鑰後,你可以用 tidycensus 的 census_api_key() 函式安裝保存,供日後使用。
本練習為示範用途,使用的是假的 API 金鑰。
本練習屬於課程
在 R 中分析美國人口普查資料
練習說明
- 在你的 DataCamp R 工作階段載入
tidycensus套件。 - 使用
census_api_key()設定 Census API 金鑰。 - 用
Sys.getenv()檢查你的 API 金鑰。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the tidycensus package into your R session
library(___)
# Define your Census API key and set it with census_api_key()
api_key <- "rw6pozt48ur2ugc8kg69x5phdrtnuhb2cb1subd6"
census_api_key(___)
# Check your API key
___("CENSUS_API_KEY")