knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" ) devtools::install()
afrobarometer
: Load Afrobarometer Data into RThe afrobarometer
automates laoding Afrobarometer Survey data into the R
environment. Open access data is downloaded as needed. The user supplies any
optional restricted access data (i.e. survey respondents georeferenced by
sampling unit). Merged data is cached in the Afrobarometer data directory and
read into R as a local data.frame
.
devtools::install_github("sboysel/afrobarometer")
The afrobarometer
package fetches any public access data necessary and merges
the available spatial data with the questionnaire data. If spatial data is not
provided for a specific round, the final table is simply the questionnaire
data.
library(afrobarometer) afrb_dir(path = "~/Dropbox/dataset/Afrobarometer")
afrb_dir
sets the local cache directory to path
, creating subdirectories
and the local database file as needed. If you have access to spatial location
data for each round, place the CSV files in the location
subdirectory of the
Afrobarometer and name them Locations_R1.csv
, Locations_R2.csv
, etc. For
example, if you have spatial information for rounds 3 and 4, your Afrobarometer
data directory should look like this after running afrb_dir
:
. ├── locations │ ├── Locations_R3.csv │ └── Locations_R4.csv ├── questionnaires └── codebooks 3 directories, 2 files
Build the database locally
afrb_build(rounds = 3:4, overwrite = TRUE)
Open access questionnaire data and codebooks are downloaded as needed and placed in the Afrobarometer data directory, \code{getOption("afrobarometer.data")}. If spatial data is available, it is merged to questionnaire data for each round. Built datasets are stored in the subdirectory \code{build} of \code{getOption("afrobarometer.data")}. The Afrobarometer directory should now have the following structure:
. ├── build │ ├── afrb_3.rds │ └── afrb_4.rds ├── locations │ ├── Locations_R3.csv │ └── Locations_R4.csv ├── questionnaires │ ├── merged_r3_data.sav │ └── merged_r4_data.sav └── codebooks ├── merged_r3_codebook2_0.pdf └── merged_r4_codebook3.pdf 4 directories, 8 files
Pull the merged Round 3 data into R
r3 <- afrb_round(round = 3)
This package simply structures the Afrobarometer data for analysis. Any use of the Afrobarometer data must comply with it's Data Usage and Access Policy. The data is protected by copywright and the authors request the following citation for any use of either the open or restricted data:
Afrobarometer Data, [Country(ies)], [Round(s)], [Year(s)], available at http://www.afrobarometer.org
rds
in build
directory.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.