
Last chance! 50% off unlimited learning
Sale ends in
data.frame
or list
-object.
To each variable, the attribute "label"
or "variable.label"
with the related variable name is attached. Most functions of the
sjPlot package can automatically retrieve the variable
name to use it as axis labels or plot title (see 'Details').set_var_labels(x, lab, attr.string = NULL)
list
of variables or a data.frame
where variables labels should be attached.x
is a vector (single variable), use a single character string with
the variable label for x
. If x
is a data frame, use a
vector with character labels of same length as ncol(x)
.
Use lab = ""
write_spss
and
x
, with attached variable label attribute(s), which contains the
variable name(s); or with removed label-attribute if
lab = ""
.get_val_labels
set_val_labels
to manually set value labels or get_var_labels
to get variable labels.# sample data set, imported from SPSS.
data(efc)
library(sjPlot)
sjt.frq(efc$e42dep)
sjt.frq(data.frame(efc$e42dep, efc$e16sex))
# manually set value and variable labels
dummy <- sample(1:4, 40, replace=TRUE)
dummy <- set_val_labels(dummy, c("very low", "low", "mid", "hi"))
dummy <- set_var_labels(dummy, "Dummy-variable")
# auto-detection of value labels by default, auto-detection of
# variable labels if parameter "title" set to NULL.
library(sjPlot)
sjp.frq(dummy, title = NULL)
# Set variable labels for data frame
dummy <- data.frame(a = sample(1:4, 10, replace = TRUE),
b = sample(1:4, 10, replace = TRUE),
c = sample(1:4, 10, replace = TRUE))
dummy <- set_var_labels(dummy,
c("Variable A",
"Variable B",
"Variable C"))
str(dummy)
# remove one variable label
dummy <- set_var_labels(dummy,
c("Variable A",
"",
"Variable C"))
str(dummy)
# setting same variable labels to multiple vectors
# create a set of dummy variables
dummy1 <- sample(1:4, 40, replace=TRUE)
dummy2 <- sample(1:4, 40, replace=TRUE)
dummy3 <- sample(1:4, 40, replace=TRUE)
# put them in list-object
dummies <- list(dummy1, dummy2, dummy3)
# and set variable labels for all three dummies
dummies <- set_var_labels(dummies, c("First Dummy", "2nd Dummy", "Third dummy"))
# see result...
get_var_labels(dummies)
Run the code above in your browser using DataLab