项目作者: tidyverse

项目描述 :
从R读取SPSS,Stata和SAS文件
高级语言: C
项目地址: git://github.com/tidyverse/haven.git
创建时间: 2015-02-04T16:28:17Z
项目社区:https://github.com/tidyverse/haven

开源协议:Other

下载


" class="reference-link">haven

CRAN
status
R-CMD-check
Codecov test
coverage

Overview

Haven enables R to read and write various data formats used by other
statistical packages by wrapping the fantastic
ReadStat C library written by
Evan Miller. Haven is part of the
tidyverse. Currently it supports:

  • SAS: read_sas() reads .sas7bdat + .sas7bcat files and
    read_xpt() reads SAS transport files (versions 5 and 8).
    write_xpt() writes SAS transport files (versions 5 and 8).

  • SPSS: read_sav() reads .sav files and read_por() reads the
    older .por files. write_sav() writes .sav files.

  • Stata: read_dta() reads .dta files (up to version 15).
    write_dta() writes .dta files (versions 8-15).

The output objects:

  • Are tibbles, which have a
    better print method for very long and very wide files.

  • Translate value labels into a new labelled() class, which preserves
    the original semantics and can easily be coerced to factors with
    as_factor(). Special missing values are preserved. See
    vignette("semantics") for more details.

  • Dates and times are converted to R date/time classes. Character
    vectors are not converted to factors.

Installation

  1. # The easiest way to get haven is to install the whole tidyverse:
  2. install.packages("tidyverse")
  3. # Alternatively, install just haven:
  4. install.packages("haven")

Usage

  1. library(haven)
  2. # SAS
  3. read_sas("mtcars.sas7bdat")
  4. write_xpt(mtcars, "mtcars.xpt")
  5. # SPSS
  6. read_sav("mtcars.sav")
  7. write_sav(mtcars, "mtcars.sav")
  8. # Stata
  9. read_dta("mtcars.dta")
  10. write_dta(mtcars, "mtcars.dta")
  • foreign reads from SAS
    XPORT, SPSS, and Stata (up to version 12) files.

  • readstat13 reads
    from and writes to all Stata file format versions.

  • sas7bdat reads from
    SAS7BDAT files.

Code of Conduct

Please note that the haven project is released with a Contributor Code
of Conduct
. By
contributing to this project, you agree to abide by its terms.