format.maskr_masked {maskr} | R Documentation |
Masked vectors generally cannot be converted to other types without unmasking them. However, they can be written as character vectors (losing the underlying masked data) for printing to the console, and saving to files.
## S3 method for class 'maskr_masked'
format(x, ..., rep = getOption("maskr.replacement", "n.p."))
## S3 method for class 'maskr_masked'
as.character(x, ..., rep = getOption("maskr.replacement", "n.p."))
x |
A masked vector. |
... |
For |
rep |
A single character value that defines a string to show instead of the underlying value for data that is masked. |
A character vector with masked values replaced by rep
.
abc <- masked(letters, letters %in% c('a', 'e', 'i', 'o', 'u'))
# Prints with default n.p. label - uses format() under the hood
print(abc)
# Format as string with * instead of n.p.
format(abc, rep = '*')
print(abc, rep = '*') # Also works with print()
as.character(abc) # Similar to format(), but without alignment
# Dispatches format to underlying data
nums <- masked(
c(1:12, NA, NA, 15:26),
rep_len(c(FALSE, FALSE, FALSE, TRUE, FALSE), 26L)
)
print(nums)
print(nums, rep = '*') # Automatically right-aligned for numeric types
# as.character() useful for saving tables without revealing data
alphanum <- data.frame(alpha = abc, num = nums)
write.csv(head(alphanum))