juba/questionr — pull request #3 by briatte (2013-07-06 13:18:46+00:00)
Title: describe – a clone of the Stata function to describe variables

This function complements the `lookfor` function by providing a quick way to describe any number of variables in a dataset, using variable labels when they have been imported with either the `foreign` or `memisc` packages.

The example shows how this works in a minimal way with standard R data frames, using one of the `questionr` example datasets (HDV 2003):

> describe(hdv2003, "age", "sexe", "lecture*", "frere|soeur")
[1] "age" "sexe" "freres.soeurs" "lecture.bd"

The function becomes more useful once a dataset has variable labels, as with this SPSS example included in the `memisc` package (ANES 1948):

> describe(nes1948, "v480050", "version|set", "v48004*")

vversion 'NES VERSION NUMBER'
vdsetno 'NES DATASET NUMBER'
v480040 '41-USA'S CNCRN W OTHERS'
v480041 '41-SATISD USA TWRD RUSS'
v480042 '41-INFORMATION LEVEL'
v480043 '41-USA GV IN,AGRT RUSS'
v480044 '41-USA-RUSS AGRT VIA U.N'
v480045 'SEX OF RESPONDENT'
v480046 'RACE OF RESPONDENT'
v480047 'AGE OF RESPONDENT'
v480048 'EDUCATION OF RESPONDENT'
v480049 'TOTAL 1948 INCOME'
v480050 'RELIGIOUS PREFERENCE'

The output is roughly similar for objects imported with `foreign`. The "*" and "|" wildcards trigger `grepl` searches to help finding variable names based on abbreviations, or to help with listing all variables in a series, as in `QA1, QA2, ..., QAx`.

This function complements `lookfor` by making it easy to access or search variable labels from R when working with survey datasets that include variable labels based on the survey questionnaire.