我正在尝试从 R 中的国家健康访谈调查中读取数据:http ://www.cdc.gov/nchs/nhis/nhis_2011_data_release.htm 。数据是成人样本。该SAScii
库实际上有一个函数read.SAScii
,其文档中有一个我想使用的相同数据集的示例。问题是它“不起作用”:
NHIS.11.samadult.SAS.read.in.instructions <-
"ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Program_Code/NHIS/2011/SAMADULT.sas"
NHIS.11.samadult.file.location <-
"ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHIS/2011/samadult.zip"
#store the NHIS file as an R data frame!
NHIS.11.samadult.df <-
read.SAScii (
NHIS.11.samadult.file.location ,
NHIS.11.samadult.SAS.read.in.instructions ,
zipped = T, )
#or store the NHIS SAS import instructions for use in a
#read.fwf function call outside of the read.SAScii function
NHIS.11.samadult.sas <- parse.SAScii( NHIS.11.samadult.SAS.read.in.instructions )
#save the data frame now for instantaneous loading later
save( NHIS.11.samadult.df , file = "NHIS.11.samadult.data.rda" )
但是,在运行它时,我得到了错误Error in toupper(SASinput) : invalid multibyte string 533
。
Stack Overflow 上的其他人也有类似的错误,但对于 和 等函数read.delim
,read.csv
建议尝试将参数更改fileEncoding="latin1"
为 例如。问题read.SAScii
是它没有这样的参数fileEncoding
。
请参阅: R:read.csv 中的无效多字节字符串和无效多字节字符串