as_string | R Documentation |
These functions convert vectors into human-readable string representations. They can join elements, create LaTeX-formatted fractions, or label observations.
as_string(txt, collapse = ", ", last = ", and ")
as_sum(txt)
as_obs(txt, name = "x", sorted = FALSE, ...)
as_fraction(val, latex = FALSE, sorted = FALSE, ...)
lobs(txt, name = "x", sorted = FALSE, ...)
lstring(txt, collapse = ", ", last = ", and ")
lfrac(val, latex = FALSE, sorted = FALSE, ...)
txt |
Character vector to merge into a single string (used in |
collapse |
Character string inserted between elements (default: |
last |
Character string used between the last two elements (default: |
name |
Character string used as the observation name (default: |
sorted |
Logical; if |
... |
Additional arguments passed to underlying functions. |
val |
Numeric vector of values to convert into fractions (used in |
latex |
Logical; if |
A single string, or a vector of formatted strings (for fractions in as_fraction
).
x <- runif(5)
y <- c(TRUE, FALSE, NA)
# Basic string conversion
as_string(x)
as_string(y)
as_string(as.character(x))
as_string(as.character(y))
# Observations
as_obs(x)
as_obs(sort(x), sorted = TRUE)
# Fraction conversion
x <- round(runif(5), 2)
as_fraction(x)
as_fraction(x, latex = TRUE)
# Summing elements as a string
y <- round(runif(5), 2)
as_sum(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.