readHFCweb | R Documentation |
This concatenates the necessary url and calls read.csv()
with all the necessary defaults to avoid annoying surprises. Age
is given as an integer, along with an AgeInterval
. The default behavior is to change the AgeInterval
column to character and produce a logical indicator column, OpenInterval
. Year
is also given as the starting year of a YearInterval
, rather than the original Year1
and Year2
columns. The column Country
is renamed CNTRY
. All other original columns are maintained. Output is invisibly returned, so you must assign it to take a look.
readHFCweb(CNTRY, item, fixup = TRUE, ...)
CNTRY |
character string of the HCD short code. Only one! Run |
item |
character string of the data product code, which is the base file name, but excluding the country code and file extension |
fixup |
logical. Default |
... |
optional arguments passed to |
## Not run: DF <- readHFCweb("CZE","TFRMAB_TOT") head(DF) DF <- readHFCweb("CZE","ASFRstand_BO") head(DF) # get ASFRstand_BO for all countries where available: Countries <- getHFCcountries() # takes a minute to run urls <- paste0("http://www.fertilitydata.org/data/", Countries,"/", Countries, "_", "ASFRstand_BO", ".txt") HaveBO <- RCurl::url.exists(urls) # we grab data for these countries: (Countries <- Countries[HaveBO]) # Also takes 1-15 min depending on internet connection and machine # read in one at a time and stick together into long data.frame allBO <- do.call(rbind, # this is the iteration of reading in lapply(Countries, function(CNTRY){ readHFCweb(CNTRY, item = "ASFRstand_BO") })) # closes off the meta-rbind thingy dim(allBO) # [1] 133237 31 unique(allBO$CNTRY) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.