| 1 |
\name{codebook} |
| 2 |
\alias{codebook} |
| 3 |
\alias{codebook,ANY-method} |
| 4 |
\alias{codebook,item-method} |
| 5 |
\alias{codebook,data.set-method} |
| 6 |
\alias{codebook,importer-method} |
| 7 |
\alias{codebook,NULL-method} |
| 8 |
\alias{codebook,atomic-method} |
| 9 |
\alias{codebook,data.frame-method} |
| 10 |
\alias{codebook,tbl_df-method} |
| 11 |
\alias{codebook,factor-method} |
| 12 |
\alias{codebook-class} |
| 13 |
\alias{format,codebookEntry-method} |
| 14 |
\alias{show,codebook-method} |
| 15 |
\alias{as.character,codebook-method} |
| 16 |
\alias{$,codebook-method} |
| 17 |
\alias{[,codebook,atomic,missing,ANY-method} |
| 18 |
\alias{[[,codebook-method} |
| 19 |
\title{Generate a Codebook of a Data Set} |
| 20 |
\description{ |
| 21 |
Function \code{codebook} collects documentation about an item, |
| 22 |
or the items in a data set or external data file. It returns |
| 23 |
an object that, when \code{show}n, print this documentation |
| 24 |
in a nicely formatted way. |
| 25 |
} |
| 26 |
\usage{ |
| 27 |
codebook(x, weights = NULL, unweighted = TRUE, \dots) |
| 28 |
\S4method{codebook}{item}(x, weights = NULL, unweighted = TRUE, \dots) |
| 29 |
\S4method{codebook}{atomic}(x, weights = NULL, unweighted = TRUE, \dots) |
| 30 |
\S4method{codebook}{factor}(x, weights = NULL, unweighted = TRUE, \dots) |
| 31 |
\S4method{codebook}{data.set}(x, weights = NULL, unweighted = TRUE, \dots) |
| 32 |
\S4method{codebook}{importer}(x, weights = NULL, unweighted = TRUE, \dots) |
| 33 |
\S4method{codebook}{data.frame}(x, weights = NULL, unweighted = TRUE, \dots) |
| 34 |
\S4method{codebook}{tbl_df}(x, weights = NULL, unweighted = TRUE, \dots) |
| 35 |
} |
| 36 |
\arguments{ |
| 37 |
\item{x}{an \code{\link{item}}, numeric or character vector, factor, |
| 38 |
\code{\link{data.set}}, \code{\link{data.frame}} or \code{\link{importer}} object for \code{codebook()}} |
| 39 |
\item{weights}{an optional vector of weights.} |
| 40 |
\item{unweighted}{an optional logical vector; if weights are given, it |
| 41 |
determines of only summaries of weighted data are show or also summaries of |
| 42 |
unweighted data.} |
| 43 |
\item{\dots}{other arguments, currently ignored.} |
| 44 |
} |
| 45 |
\value{ |
| 46 |
An object of class "codebook", for which a \code{\link{show}} method exists that |
| 47 |
produces a nicely formatted output. |
| 48 |
} |
| 49 |
\examples{ |
| 50 |
|
| 51 |
Data <- data.set( |
| 52 |
vote = sample(c(1,2,3,8,9,97,99),size=300,replace=TRUE), |
| 53 |
region = sample(c(rep(1,3),rep(2,2),3,99),size=300,replace=TRUE), |
| 54 |
income = exp(rnorm(300,sd=.7))*2000 |
| 55 |
) |
| 56 |
|
| 57 |
Data <- within(Data,{ |
| 58 |
description(vote) <- "Vote intention" |
| 59 |
description(region) <- "Region of residence" |
| 60 |
description(income) <- "Household income" |
| 61 |
wording(vote) <- "If a general election would take place next tuesday, |
| 62 |
the candidate of which party would you vote for?" |
| 63 |
wording(income) <- "All things taken into account, how much do all |
| 64 |
household members earn in sum?" |
| 65 |
foreach(x=c(vote,region),{ |
| 66 |
measurement(x) <- "nominal" |
| 67 |
}) |
| 68 |
measurement(income) <- "ratio" |
| 69 |
labels(vote) <- c( |
| 70 |
Conservatives = 1, |
| 71 |
Labour = 2, |
| 72 |
"Liberal Democrats" = 3, |
| 73 |
"Don't know" = 8, |
| 74 |
"Answer refused" = 9, |
| 75 |
"Not applicable" = 97, |
| 76 |
"Not asked in survey" = 99) |
| 77 |
labels(region) <- c( |
| 78 |
England = 1, |
| 79 |
Scotland = 2, |
| 80 |
Wales = 3, |
| 81 |
"Not applicable" = 97, |
| 82 |
"Not asked in survey" = 99) |
| 83 |
foreach(x=c(vote,region,income),{ |
| 84 |
annotation(x)["Remark"] <- "This is not a real survey item, of course ..." |
| 85 |
}) |
| 86 |
missing.values(vote) <- c(8,9,97,99) |
| 87 |
missing.values(region) <- c(97,99) |
| 88 |
}) |
| 89 |
|
| 90 |
description(Data) |
| 91 |
|
| 92 |
codebook(Data) |
| 93 |
|
| 94 |
codebook(Data)$vote |
| 95 |
codebook(Data)[2] |
| 96 |
|
| 97 |
codebook(Data[2]) |
| 98 |
|
| 99 |
DataFr <- as.data.frame(Data) |
| 100 |
DataHv <- as_haven(Data,user_na=TRUE) |
| 101 |
|
| 102 |
codebook(DataFr) |
| 103 |
codebook(DataHv) |
| 104 |
|
| 105 |
|
| 106 |
\dontrun{ |
| 107 |
Write(description(Data), |
| 108 |
file="Data-desc.txt") |
| 109 |
Write(codebook(Data), |
| 110 |
file="Data-cdbk.txt") |
| 111 |
} |
| 112 |
} |
| 113 |
\keyword{manip} |