View source: R/label_from_names.R
| label_from_names | R Documentation |
name<sep>labelSplits each column name at the first occurrence of sep, renames
the column to the part before sep (the name), and assigns the part
after sep as a labelled::var_label(). This works even if the label
itself contains the separator.
label_from_names(df, sep = ". ")
df |
A |
sep |
Character string used as separator between name and label.
Default is |
This function is especially useful for LimeSurvey CSV exports when using
Export results → Export format: CSV → Headings: Question code & question text,
where column names look like "code. question text". In this case the
default separator is ". ".
A base tibble with column names equal to the names (before sep)
and var_label attributes equal to the labels (after sep).
# Example with LimeSurvey-style column names
df <- data.frame(
"age. Age of respondent" = c(25, 30),
"score. Total score. Manually computed." = c(12, 14),
check.names = FALSE
)
# sep = ". " by default (LimeSurvey)
out <- label_from_names(df)
labelled::var_label(out)
# Example with a custom separator ("|")
df2 <- data.frame(
"id|Identifier" = 1:3,
"score|Total score" = c(10, 20, 30),
check.names = FALSE
)
out2 <- label_from_names(df2, sep = "|")
labelled::var_label(out2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.