當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R haven read_sas 讀取 SAS 文件

read_sas() 支持 SAS 用於記錄值標簽的 sas7bdat 文件和隨附的 sas7bcat 文件。

用法

read_sas(
  data_file,
  catalog_file = NULL,
  encoding = NULL,
  catalog_encoding = encoding,
  col_select = NULL,
  skip = 0L,
  n_max = Inf,
  cols_only = deprecated(),
  .name_repair = "unique"
)

參數

data_file, catalog_file

數據和目錄文件的路徑。這些文件使用 readr::datasource() 進行處理。

encoding, catalog_encoding

分別用於data_filecatalog_encoding 的字符編碼。 NULL 的值使用文件中指定的編碼;如果不正確,請使用此參數來覆蓋它。

col_select

一個或多個選擇表達式,例如 dplyr::select() 。使用c()list() 來使用多個表達式。有關可用選擇選項的詳細信息,請參閱?dplyr::select。僅從 data_file 讀取指定的列。

skip

讀取數據之前要跳過的行數。

n_max

讀取的最大行數。

cols_only

[Deprecated] cols_only不再支持;使用col_select反而。

.name_repair

有問題的列名的處理:

  • "minimal":沒有名稱修複或檢查,超出基本存在,

  • "unique" :確保名稱唯一且不為空,

  • "check_unique" :(默認值),沒有名稱修複,但檢查它們是 unique

  • "universal" :命名為 unique 和語法

  • 函數:應用自定義名稱修複(例如,.name_repair = make.names 用於基本 R 樣式的名稱)。

  • purrr-style 匿名函數,請參閱rlang::as_function()

此參數作為 repair 傳遞到 vctrs::vec_as_names() 。有關這些條款以及用於執行這些條款的策略的更多詳細信息,請參閱此處。

一個 tibble DataFrame 變體,具有很好的默認值。

變量標簽存儲在每個變量的"label"屬性中。它不會打印在控製台上,但 RStudio 查看器會顯示它。

write_sas() 以不可見方式返回輸入data

例子

path <- system.file("examples", "iris.sas7bdat", package = "haven")
read_sas(path)
#> # A tibble: 150 × 5
#>    Sepal_Length Sepal_Width Petal_Length Petal_Width Species
#>           <dbl>       <dbl>        <dbl>       <dbl> <chr>  
#>  1          5.1         3.5          1.4         0.2 setosa 
#>  2          4.9         3            1.4         0.2 setosa 
#>  3          4.7         3.2          1.3         0.2 setosa 
#>  4          4.6         3.1          1.5         0.2 setosa 
#>  5          5           3.6          1.4         0.2 setosa 
#>  6          5.4         3.9          1.7         0.4 setosa 
#>  7          4.6         3.4          1.4         0.3 setosa 
#>  8          5           3.4          1.5         0.2 setosa 
#>  9          4.4         2.9          1.4         0.2 setosa 
#> 10          4.9         3.1          1.5         0.1 setosa 
#> # ℹ 140 more rows
源代碼:R/haven-sas.R

相關用法


注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Read SAS files。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。