| Title: | Working with Labelled Data on Steroids |
|---|---|
| Description: | Labelled data is ubiquitous. Package 'lablah' provides extra tools for creating, working, and reporting based on labelled data. |
| Authors: | Michal Bojanowski [aut, cre] (ORCID: <https://orcid.org/0000-0001-7503-852X>) |
| Maintainer: | Michal Bojanowski <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1-1 |
| Built: | 2026-05-28 07:45:39 UTC |
| Source: | https://github.com/mbojan/lablah |
Generate a codebook based on data documentation (variable names, variable labels, and value labels).
cdbk_df(data) cdbk_dt(data, ...)cdbk_df(data) cdbk_dt(data, ...)
data |
labelled tibble |
... |
other arguments passed to |
Function cdbk_df() returns a tibble with columns:
variable - variable name
label - variable label
value_labels - list of tibbles with value labels
Function cdbk_dt() uses DT::datatable() to generate a browsable
and searchable codebook based on the documentation.
Frequency tibble
freq_df(data, var = -1, name = NULL, ...)freq_df(data, var = -1, name = NULL, ...)
data |
data frame |
var |
Variable name or index (negative counting from the right, positive
counting from the left), see |
name |
Column which values will be used as names. Specified as |
... |
other arguments |
Lists and tibbles with user missing values
misvals(data) misranges(data) misranges_df(data)misvals(data) misranges(data) misranges_df(data)
data |
Labelled tibble with missing values/ranges defined |
Function misvals() returns a list of vectors of missing values (or
NULLs if none are defined). List elements are named with variable names.
Function misranges() returns a list of two-element vectors with
ranges of missing values.
Function misranges_df() returns a tibble with columns
variable - Variable name
from, to - Bounds (inclusive) of the missing value range
Given a vector x guess what kind of "type" it is, where "type"
correspond to some common classes influencing useful ways to
analyze/visualize. These functions are used internally to determine default
behavior of some other functions.
seems_integer() – Returns TRUE if x is typeof()
integer or is a numeric with all values being in fact integers (i.e. equal
to round(x)).
seems_continuous() – Returns TRUE if x is numeric and,
if an integer, has more than 10 distinct values.
seems_discrete() – Returns TRUE if x does not seem to
be continuous.
seems_categorical() -
seems_integer(x) seems_continuous(x) seems_discrete(x) seems_categorical(x)seems_integer(x) seems_continuous(x) seems_discrete(x) seems_categorical(x)
x |
a vector for which |
All seems_*() functions return TRUE or FALSE (a logical
scalar).
# seems_integer() ---------------------------------------------------------- seems_integer(1:5) # TRUE seems_integer(runif(5)) # FALSE # seems_continuous() ------------------------------------------------------- seems_continuous(1:5) # FALSE seems_continuous(1:11) # TRUE seems_continuous(runif(5)) # TRUE # Summarize variables of `mtcars` in a type-dependent way by drawing a # histogram for continuous ones and barchart with counts for non-continuous # ones. iscont <- vapply(mtcars, seems_continuous, logical(1)) layout(matrix(1:12, 3, 4)) for(n in names(mtcars)) { if(iscont[n]) { hist(mtcars[[n]], main=n, xlab="") } else { barplot(table(mtcars[[n]]), main=n) } } layout(1)# seems_integer() ---------------------------------------------------------- seems_integer(1:5) # TRUE seems_integer(runif(5)) # FALSE # seems_continuous() ------------------------------------------------------- seems_continuous(1:5) # FALSE seems_continuous(1:11) # TRUE seems_continuous(runif(5)) # TRUE # Summarize variables of `mtcars` in a type-dependent way by drawing a # histogram for continuous ones and barchart with counts for non-continuous # ones. iscont <- vapply(mtcars, seems_continuous, logical(1)) layout(matrix(1:12, 3, 4)) for(n in names(mtcars)) { if(iscont[n]) { hist(mtcars[[n]], main=n, xlab="") } else { barplot(table(mtcars[[n]]), main=n) } } layout(1)
Extract value labels and return as tibble(s)
vallabs(object, ...) ## Default S3 method: vallabs(object, ...) ## S3 method for class 'data.frame' vallabs(object, ...)vallabs(object, ...) ## Default S3 method: vallabs(object, ...) ## S3 method for class 'data.frame' vallabs(object, ...)
object |
R object, typically a vector or data frame. See below for available methods |
... |
other arguments to/from other methods. Currently ignored. |
The default method returns a single tibble with columns:
label - Value label
value - Value
If object is a data frame vallabs() returns a list of tibbles (or
NULLs of no value labels are present) named with variable names. Each
tibble has columns as described in the default method.
default: Extract value labels and return a tibble.
data.frame: Extract value labels from all the columns and return a list of tibbles.
Tibble of variable labels
varlabs(data)varlabs(data)
data |
data frame with labelled variables |
A tibble with columns
variable - Variable name
label - Variable label