各位大神,怎么把SPSS数据导入R里面的?为什么我的导不了

0

W19XCWS)ZSVMB]MZUVEKFZI.png

 
已邀请:
0

marxsong 2016-11-16 回答

spss.get一般读取spss的 .sav文件,你代码中好像没不是:
w <- spss.get('/……/****.sav')
 
也可以参考stackoverflow的方法:
1) There is a IBM SPSS Statistics Data File Driver. I could not find the download link. I got it from my SPSS provider. The Standalone Driver is all you need. You do not need SPSS to install or use the driver.

2) Create a DSN for the SPSS data driver.

3) Using RODBC package you can read in R any SPSS data file. It will be possible to get value labels for each variable as separate tables.
 
require(RODBC)

# Create connection
# Change the DSN name and CP_CONNECT_STRING according to your setting
con <- odbcDriverConnect("DSN=spss_ehsis;SDSN=SAVDB;HST=C:\\Program Files\\IBM\\SPSS\\StatisticsDataFileDriver\\20\\Standalone\\cfg\\oadm.ini;PRT=StatisticsSAVDriverStandalone;CP_CONNECT_STRING=C:\\temp\\data_expt.sav")

# List of tables
Tables <- sqlTables(con)
Tables

# List of table names to extract
table.names <- Tables$TABLE_NAME[Tables$TABLE_SCHEM != "SYSTEM"]

# Function to query a table by name
sqlQuery.tab.name <- function(table) {
sqlQuery(con, paste0("SELECT * FROM [", table, "]"))
}

# Retrieve all tables
Data <- lapply(table.names, sqlQuery.tab.name)

# See the data
lapply(Data, head)

# Close connection
close(con)
0

谢佳标 - 微软中国MVP,多届中国R语言大会演讲嘉宾。 从事数据挖掘建模工作已有10年, 曾经从事过咨询、电商、电购、电力、游戏、金融等行业,了解不同领域的数据特点。 有丰富的利用R语言进行数据挖掘实战经验。 合著《R语言与数据挖掘》及《数据实践之美》等书籍,均在京东有卖。此外《R语言游戏数据分析与挖掘》预计将在2017年上半年出版。 2016-11-29 回答

foreign包也有函数可以实现

要回复问题请先登录注册