恢复DBL+ lbl变量

发布于 2025-02-08 04:34:32 字数 287 浏览 2 评论 0原文

我需要录制使用Haven导入的一些变量。 变量标记为DBL+LBL。

0 = [no]
1 = [yes]

我需要将此变量重新描述为

1 = [yes]
2=  [no]

我使用的: data_muenster $性别[data_muenster $ gender == 0]< - 2

在这种情况下,当然值正确地重新编码了值,但是我没有2个;有没有办法一次重新编码价值和标签?

I need to recorde some variables I imported using haven.
The variables are dbl+lbl labelled.

0 = [no]
1 = [yes]

I need to recode this variable to

1 = [yes]
2=  [no]

I used:
data_MUENSTER$gender[data_MUENSTER$gender == 0 ] <- 2

In this case of course the value is recoded correctly, but I have no lable for 2; Is there a way to recoded value and label at once?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2025-02-15 04:34:33

您应该能够通过标记的软件包的某些版本的set_value_labels来实现此目标。

df |>
mutate(x, ~set_value_labels(., c("Yes" = 1, "No" = 2))))

You should be able to achieve this with some version of set_value_labels from the labelled package.

df |>
mutate(x, ~set_value_labels(., c("Yes" = 1, "No" = 2))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文