gpt4 book ai didi

r - R 包中的变量标签 Haven with SPSS

转载 作者:行者123 更新时间:2023-12-04 08:02:48 25 4
gpt4 key购买 nike

我正在尝试从带有haven 包的SPSS por 文件访问变量标签(这是变量的描述)。我可以用外国包做得很好,但我想使用haven。有什么建议?

# Using foreign I can get the variable labels
with_foreign <- foreign::read.spss(mydata.por)
attr(with_foreign, "variable.labels")

# With haven I get null
with_haven <- haven::read_spss(mydata.por)
attr(with_haven, "variable.labels")

# Some things I've experimented with
labelled::var_label(with_haven) # NULL
attributes(with_haven) # Not useful
as_factor(with_haven$var1) # Gives me definitions for factor levels (not what I need)

最佳答案

read_spss 中所述标签存储为每列的属性,而不是 data.frame 的属性。 .尝试

lapply(with_haven, function(x) attributes(x)$label)

关于r - R 包中的变量标签 Haven with SPSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48818985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com