"Tagged" 缺失值的工作方式與常規 R 缺失值完全相同,隻是它們在標簽中存儲一個額外的信息字節,通常是一個字母("a" 到 "z")。加載 SAS 和 Stata 文件時,標記的缺失值始終使用小寫值。
用法
tagged_na(...)
na_tag(x)
is_tagged_na(x, tag = NULL)
format_tagged_na(x, digits = getOption("digits"))
print_tagged_na(x, digits = getOption("digits"))
例子
x <- c(1:5, tagged_na("a"), tagged_na("z"), NA)
# Tagged NA's work identically to regular NAs
x
#> [1] 1 2 3 4 5 NA NA NA
is.na(x)
#> [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE
# To see that they're special, you need to use na_tag(),
# is_tagged_na(), or print_tagged_na():
is_tagged_na(x)
#> [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE
na_tag(x)
#> [1] NA NA NA NA NA "a" "z" NA
print_tagged_na(x)
#> [1] 1 2 3 4 5 NA(a) NA(z) NA
# You can test for specific tagged NAs with the second argument
is_tagged_na(x, "a")
#> [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE
# Because the support for tagged's NAs is somewhat tagged on to R,
# the left-most NA will tend to be preserved in arithmetic operations.
na_tag(tagged_na("a") + tagged_na("z"))
#> [1] "a"
相關用法
- R haven read_xpt 讀寫 SAS 傳輸文件
- R haven zap_missing 將特殊缺失修改為常規 R 缺失
- R haven print_labels 打印帶標簽向量的標簽
- R haven zap_label Zap 變量標簽
- R haven read_sas 讀取 SAS 文件
- R haven labelled 創建一個標記向量。
- R haven read_dta 讀寫Stata DTA文件
- R haven as_factor 將標記向量轉換為因子
- R haven read_spss 讀取和寫入 SPSS 文件
- 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等大神的英文原創作品 "Tagged" missing values。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。