- Hands-On Data Science with Anaconda
- Dr. Yuxing Yan James Yan
- 170字
- 2021-06-25 21:08:51
Introduction to the haven and foreign R packages
The R package called haven is for import and export from SPSS, Stata and SAS files. The package is for Labelled Data Utility Functions, which is a collection of many small functions dealing with labelled data, such as reading and writing data between R and other statistical software packages such as SAS, SPSS, or Stata, and working with labelled data.
This includes easy ways to get, set, and change value and variable label attributes, convert labelled vectors into factors or numeric values (and vice versa), and deal with multiple declared missing values. The following example is about writing several specific outputs:
library(haven)
x<-1:100
y<-matrix(x,50,2)
z<-data.frame(y)
colnames(z)<-c("a","b")
write_sas(z,"c:/temp/tt.sas7bdat")
write_spss(z,"c:/temp/tt.sav")
write_stata(z,"c:/temp/tt.dta")
Another R package called foreign can be used to read SPSS, and SAS data. Here is one example. First, let's download a SPSS dataset called airline_passanges.sav at http://calcnet.mth.cmich.edu/org/spss/Prj_airlinePassengers.htm. Assume that the related SPCC data is saved under c:/temp:
library(foreign) x<-read.spss("c:/temp/airline_passengers.sav", to.data.frame=TRUE) dim(x) [1] 144 1
- Excel 2007函數與公式自學寶典
- Hadoop 2.x Administration Cookbook
- Practical Data Wrangling
- Visual FoxPro 6.0數據庫與程序設計
- 電腦上網直通車
- 大數據挑戰與NoSQL數據庫技術
- Photoshop CS3特效處理融會貫通
- 現代機械運動控制技術
- Docker High Performance(Second Edition)
- Mastering Game Development with Unreal Engine 4(Second Edition)
- 手機游戲程序開發
- 電子設備及系統人機工程設計(第2版)
- 精通LabVIEW程序設計
- 從零開始學JavaScript
- 未來學徒:讀懂人工智能飛馳時代