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
です。