ez.labels.set: set value labels, wrapper of 'sjmisc_set_labels'.

ez.labels.setR Documentation

set value labels, wrapper of sjmisc_set_labels.

Description

set value labels, wrapper of sjmisc_set_labels.

Usage

ez.labels.set(x, valuelabels, force.labels = FALSE, force.values = FALSE, ...)

ez.setlabels(x, valuelabels, force.labels = FALSE, force.values = FALSE, ...)

Value

returns a new changed var

Note

The usage of the original function is a bit confusing. Here, I summarize:
1) Always use a named vector for valuelabels, in which case force.labels and force.values will be ignored
valuelabels:
1 4 5 9 do not have to all appear in x, that is, you can assign more labels than values (or vice versa, assign less labels)
notice the particular order and symbol: "strongly agree" <- 1
sjmisc_set_labels(x, c("strongly agree"=1,"totally disagree"=4,"refused"=5,"missing"=9))
This format is flipped from the results directly from ez.getlabels

2) when valuelabels="", essentially clear value labels attribute

3) if no exisiting attr, using haven style: labels

4) though x could be df, I generally use x as var

example: df$gradelevel = ez.setlabels(df$gradelevel, c("freshman"=1,"Sophomore"=2,"Junior"=3,"Senior"=4))

See Also

gather, spread, separate, unite
select, slice
distinct, arrange
summarise, count, mutate
group_by, left_join, right_join, inner_join, full_join, semi_join, anti_join
intersect, union, setdiff
bind_rows, bind_cols

Other data transformation functions: ez.2char(), ez.2factor(), ez.2label(), ez.2long(), ez.2lower(), ez.2value(), ez.2wide(), ez.compute(), ez.del(), ez.label.get(), ez.label.set(), ez.labels.get(), ez.move(), ez.newcol(), ez.num(), ez.recode(), ez.recols(), ez.recol(), ez.rename(), ez.replace(), ez.rncols(), ez.rncol(), ez.select(), ez.sort(), ez.split(), ez.str(), ez.unique(), left_join()


jerryzhujian9/zmisc documentation built on March 9, 2024, 12:49 a.m.