This method counts tagged NA values (see tagged_na
)
in a vector and prints a frequency table of counted tagged NAs.
count_na(x, ...)
A vector or data frame.
Optional, unquoted names of variables that should be selected for
further processing. Required, if x
is a data frame (and no
vector) and only selected variables from x
should be processed.
You may also use functions like :
or tidyselect's
select-helpers.
See 'Examples' or package-vignette.
A data frame with counted tagged NA values.
if (require("haven")) {
x <- labelled(
x = c(1:3, tagged_na("a", "c", "z"),
4:1, tagged_na("a", "a", "c"),
1:3, tagged_na("z", "c", "c"),
1:4, tagged_na("a", "c", "z")),
labels = c("Agreement" = 1, "Disagreement" = 4,
"First" = tagged_na("c"), "Refused" = tagged_na("a"),
"Not home" = tagged_na("z"))
)
count_na(x)
y <- labelled(
x = c(1:3, tagged_na("e", "d", "f"),
4:1, tagged_na("f", "f", "d"),
1:3, tagged_na("f", "d", "d"),
1:4, tagged_na("f", "d", "f")),
labels = c("Agreement" = 1, "Disagreement" = 4, "An E" = tagged_na("e"),
"A D" = tagged_na("d"), "The eff" = tagged_na("f"))
)
# create data frame
dat <- data.frame(x, y)
# possible count()-function calls
count_na(dat)
count_na(dat$x)
count_na(dat, x)
count_na(dat, x, y)
}
#> Loading required package: haven
#>
#> Attaching package: ‘haven’
#> The following objects are masked from ‘package:sjlabelled’:
#>
#> as_factor, read_sas, read_spss, read_stata, write_sas, zap_labels
#> label frq raw.prc valid.prc cum.prc
#> 1 First 5 41.67 41.67 41.67
#> 2 Not home 3 25.00 25.00 66.67
#> 3 Refused 4 33.33 33.33 100.00
#>
#> # x
#>
#> label frq raw.prc valid.prc cum.prc
#> 1 First 5 41.67 41.67 41.67
#> 2 Not home 3 25.00 25.00 66.67
#> 3 Refused 4 33.33 33.33 100.00
#>
#>
#> # y
#>
#> label frq raw.prc valid.prc cum.prc
#> 1 A D 5 41.67 41.67 41.67
#> 2 An E 1 8.33 8.33 50.00
#> 3 The eff 6 50.00 50.00 100.00
#>
#>
#> label frq raw.prc valid.prc cum.prc
#> 1 First 5 41.67 41.67 41.67
#> 2 Not home 3 25.00 25.00 66.67
#> 3 Refused 4 33.33 33.33 100.00
#>
#> # x
#>
#> label frq raw.prc valid.prc cum.prc
#> 1 First 5 41.67 41.67 41.67
#> 2 Not home 3 25.00 25.00 66.67
#> 3 Refused 4 33.33 33.33 100.00
#>
#>
#> # x
#>
#> label frq raw.prc valid.prc cum.prc
#> 1 First 5 41.67 41.67 41.67
#> 2 Not home 3 25.00 25.00 66.67
#> 3 Refused 4 33.33 33.33 100.00
#>
#>
#> # y
#>
#> label frq raw.prc valid.prc cum.prc
#> 1 A D 5 41.67 41.67 41.67
#> 2 An E 1 8.33 8.33 50.00
#> 3 The eff 6 50.00 50.00 100.00
#>
#>