v <- labelled(
c(1, 2, 2, 2, 3, 9, 1, 3, 2, NA),
c(yes = 1, no = 3, "don't know" = 9)
)
to_character(v)
to_character(v, nolabel_to_na = TRUE)
to_character(v, "v")
to_character(v, "p")
df <- data.frame(
a = labelled(c(1, 1, 2, 3), labels = c(No = 1, Yes = 2)),
b = labelled(c(1, 1, 2, 3), labels = c(No = 1, Yes = 2, DK = 3)),
c = labelled(
c("a", "a", "b", "c"),
labels = c(No = "a", Maybe = "b", Yes = "c")
),
d = 1:4,
e = factor(c("item1", "item2", "item1", "item2")),
f = c("itemA", "itemA", "itemB", "itemB"),
stringsAsFactors = FALSE
)
if (require(dplyr)) {
glimpse(df)
glimpse(to_character(df))
glimpse(to_character(df, labelled_only = FALSE))
}
Run the code above in your browser using DataLab