当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R haven zap_label Zap 变量标签


删除变量标签,保留未标记的向量。

用法

zap_label(x)

参数

x

向量或 DataFrame

也可以看看

zap_labels() 删除值标签。

其他灭杀器:zap_empty()zap_formats()zap_labels()zap_widths()

例子

x1 <- labelled(1:5, c(good = 1, bad = 5), label = "rating")
x1
#> <labelled<integer>[5]>: rating
#> [1] 1 2 3 4 5
#> 
#> Labels:
#>  value label
#>      1  good
#>      5   bad
zap_label(x1)
#> <labelled<integer>[5]>
#> [1] 1 2 3 4 5
#> 
#> Labels:
#>  value label
#>      1  good
#>      5   bad

x2 <- labelled_spss(c(1:4, 9), label = "score", na_values = 9)
x2
#> <labelled_spss<double>[5]>: score
#> [1] 1 2 3 4 9
#> Missing values: 9
zap_label(x2)
#> <labelled_spss<double>[5]>
#> [1] 1 2 3 4 9
#> Missing values: 9

# zap_label also works with data frames
df <- tibble::tibble(x1, x2)
str(df)
#> tibble [5 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ x1: int+lbl [1:5] 1, 2, 3, 4, 5
#>    ..@ labels: Named int [1:2] 1 5
#>    .. ..- attr(*, "names")= chr [1:2] "good" "bad"
#>    ..@ label : chr "rating"
#>  $ x2: dbl+lbl [1:5] 1, 2, 3, 4, 9
#>    ..@ label    : chr "score"
#>    ..@ na_values: num 9
str(zap_label(df))
#> tibble [5 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ x1: int+lbl [1:5] 1, 2, 3, 4, 5
#>    ..@ labels: Named int [1:2] 1 5
#>    .. ..- attr(*, "names")= chr [1:2] "good" "bad"
#>  $ x2: dbl+lbl [1:5] 1, 2, 3, 4, 9
#>    ..@ na_values: num 9
源代码:R/zap_label.R

相关用法


注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Zap variable labels。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。