Loading datasets from the Internet
The most obvious task is to download datasets from the Web and load those into our R session in two manual steps:
- Save the datasets to disk.
- Read those with standard functions, such as
read.table
or for exampleforeign::read.spss
, to importsav
files.
But we can often save some time by skipping the first step and loading the flat text data files directly from the URL. The following example fetches a comma-separated file from the Americas Open Geocode (AOG) database at http://opengeocode.org, which contains the government, national statistics, geological information, and post office websites for the countries of the world:
> str(read.csv('http://opengeocode.org/download/CCurls.txt')) 'data.frame': 249 obs. of 5 variables: $ ISO.3166.1.A2 : Factor w/ 248 levels "AD" ... $ Government.URL : Factor w/ 232 levels "" ... $ National.Statistics.Census..URL: Factor w/ 213 levels "...