【发布时间】:2021-11-17 20:14:53
【问题描述】:
我正在尝试编写一个包含一些 haven_labelled 变量和从该变量创建的因子的 SPSS 文件。我和我的用例使用几乎相同的变量名很方便。我为have_labelled变量使用了所有小写字母,为各个因子变量使用了标题。
当我用write_sav 导出数据框时,SPSS 用var1 记录标题大小写因子的变量名称,而不是标题大小写,在本例中为Francophone。请注意,当我显着更改变量名称时,它会打印变量名称。
#This makes the data frame of haven labelled variable and a corresponding factor
test<-structure(list(francophone = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), labels = c(Francophone = 1, `Not Francophone` = 0), label = "Dichotomous variable, R is francophone", class = c("haven_labelled", "vctrs_vctr", "double")), Francophone = structure(c(1L, 1L, 1L,1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Not Francophone", "Francophone"), label = "Dichotomous variable, R is francophone", class = "factor")), row.names = c(NA,-10L), class = c("tbl_df", "tbl", "data.frame"))
#Create a second factor variable equivalent to the first factor, but with a different variable name
test$Franco<-test$Francophone
library(tidyverse)
library(haven)
#Write out the file; sorry I do not know how to use tmpfile() in this case.
test %>%
write_sav(., path="~/Desktop/test2.sav")
【问题讨论】:
-
你的问题是什么?您可能想熟悉 SPSS 中变量命名的要求,即您不能有相同的变量名称,其中 SPSS 中的相同也意味着忽略大写/小写。
-
我以为我在标题中提出了问题。问题是我如何写入一个不同的 sav 文件以防万一。但是我在这里和其他地方了解到 SPSS 不区分大小写地处理变量,所以这是不可能的。谢谢!