Collapse to string
Usage
collapseToString(object, ...)
# S4 method for DFrame
collapseToString(object, sep = ", ", sort = FALSE, unique = FALSE)
# S4 method for atomic
collapseToString(object, sep = ", ", sort = FALSE, unique = FALSE)
# S4 method for data.frame
collapseToString(object, sep = ", ", sort = FALSE, unique = FALSE)
# S4 method for matrix
collapseToString(object, sep = ", ", sort = FALSE, unique = FALSE)
Arguments
- object
Object.
- sep
character(1)
. Separator. Defaults to comma.- sort
logical(1)
. Sort values.- unique
logical(1)
. Unique values.- ...
Additional arguments.
Examples
## character ====
groceries <- c(NA, NA, "milk", "eggs", "eggs", "veggies")
collapseToString(
groceries,
unique = TRUE,
sort = TRUE
)
#> [1] "eggs, milk, veggies, NA"
collapseToString(
groceries,
unique = FALSE,
sort = FALSE
)
#> [1] "NA, NA, milk, eggs, eggs, veggies"
## numeric ====
collapseToString(seq(1:5))
#> [1] "1, 2, 3, 4, 5"
## logical ====
collapseToString(c(TRUE, FALSE))
#> [1] "TRUE, FALSE"
collapseToString(c(NA, NaN))
#> [1] "NA, NaN"
## data.frame ====
df <- datasets::iris
df <- head(df)
df <- collapseToString(df, sort = TRUE, unique = TRUE)
t(df)
#> [,1]
#> Sepal.Length "4.6, 4.7, 4.9, 5, 5.1, 5.4"
#> Sepal.Width "3, 3.1, 3.2, 3.5, 3.6, 3.9"
#> Petal.Length "1.3, 1.4, 1.5, 1.7"
#> Petal.Width "0.2, 0.4"
#> Species "setosa"