Jilei Zhou Jilei Zhou - 3 months ago 22
R Question

Read SPSS file into R, the data format for date is wrong, and generate more variable

I have tried using spss.get from Hmisc.
Here is my code:

install.packages("Hmisc")
library(Hmisc)
mydata <- spss.get("C:\\good good study\\comscore\\purchase.sav", use.value.labels = TRUE)


the output is shown with warning message which is as follows:

> mydata <- spss.get("C:\\good good study\\comscore\\purchase.sav", use.value.labels = TRUE)
Warning messages:
1: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame, :
C:\good good study\comscore\purchase.sav: Unrecognized record type 7, subtype 14 encountered in system file
2: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame, :
C:\good good study\comscore\purchase.sav: Unrecognized record type 7, subtype 18 encountered in system file


My initial date in spss is as follow:
date in spss is correct

However, when I use spss.get in R, the data for date becomes garbled:
date become garbled in R

Answer

This is a number of seconds from some specific time what you see in R. You can convert it to date or time. For example:

z <- c(10485849601, 10477641600, 10561104000, 10562745600)
as.POSIXct(z, origin="1582-10-14", tz="GMT")

For time values probably the best option is to use the chron library. See the example:

require(chron)
y <- c(58130, 10981)
chron(times. = y / (24*60*60))

Have you tried the haven package for reading the SPSS data?