如何在R中读取.sav SPSS文件?

时间:2013-05-23 17:49:19

标签: r character-encoding statistics spss cp1252

我已经尝试过read.spps(),但是我遇到了编码错误:

> library(foreign)
> read.spss('persona.sav')
re-encoding from CP1252
Error in iconv(names(rval), cp, "") : 
  unsupported conversion from 'CP1252' to ''
In addition: Warning message:
In read.spss("persona.sav") :
  persona.sav: Unrecognized record type 7, subtype 18 encountered in system file

2 个答案:

答案 0 :(得分:8)

尝试将其重新编码为utf-8文件:

> library(foreign)
> read.spss('persona.sav', reencode='utf-8')

答案 1 :(得分:0)

您可以尝试将'to.data.frame = TRUE'添加到read.spss()

例如:

df <- read.spss("data.sav", to.data.frame = TRUE)