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_file
和catalog_encoding
的字符編碼。NULL
的值使用文件中指定的編碼;如果不正確,請使用此參數來覆蓋它。 - col_select
-
一個或多個選擇表達式,例如
dplyr::select()
。使用c()
或list()
來使用多個表達式。有關可用選擇選項的詳細信息,請參閱?dplyr::select
。僅從data_file
讀取指定的列。 - skip
-
讀取數據之前要跳過的行數。
- n_max
-
讀取的最大行數。
- cols_only
- .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 read_spss 讀取和寫入 SPSS 文件
- R haven read_xpt 讀寫 SAS 傳輸文件
- R haven read_dta 讀寫Stata DTA文件
- R haven zap_missing 將特殊缺失修改為常規 R 缺失
- R haven print_labels 打印帶標簽向量的標簽
- R haven tagged_na “標記”缺失值
- R haven zap_label Zap 變量標簽
- R haven labelled 創建一個標記向量。
- R haven as_factor 將標記向量轉換為因子
- R haven zap_empty 將空字符串轉換為缺失值
- R haven labelled_spss SPSS 的標記向量
- R haven zap_labels Zap值標簽
- R SparkR hashCode用法及代碼示例
- R hms hms 用於存儲一天中的時間值的簡單類
- R SparkR hint用法及代碼示例
- R hms parse_hms 解析 hms 值
- R SparkR histogram用法及代碼示例
- R SparkR head用法及代碼示例
- R hms round_hms 四舍五入或截斷為秒的倍數
- R dtrMatrix-class 三角形稠密數值矩陣
- R vcov.gam 從 GAM 擬合中提取參數(估計器)協方差矩陣
- R gam.check 擬合 gam 模型的一些診斷
- R ggplot2 annotation_logticks 注釋:記錄刻度線
- R matrix轉list用法及代碼示例
- R Pixel X 射線像素強度隨時間的變化
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Read SAS files。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。