Collapse to string

collapseToString(object, ...)

# S4 method for atomic
collapseToString(object, sep = ", ", sort = FALSE,
  removeNA = FALSE, unique = FALSE)

# S4 method for matrix
collapseToString(object, sep = ", ", sort = FALSE,
  removeNA = FALSE, unique = FALSE)

# S4 method for data.frame
collapseToString(object, sep = ", ",
  sort = FALSE, removeNA = FALSE, unique = FALSE)

# S4 method for DataFrame
collapseToString(object, sep = ", ",
  sort = FALSE, removeNA = FALSE, unique = FALSE)

Arguments

object

Object.

sep

character(1). Separator. Defaults to comma.

sort

logical(1). Sort values.

removeNA

logical(1). Remove NA values.

unique

logical(1). Unique values.

...

Additional arguments.

Value

  • atomic: character(1).

  • dim: Object of same class, collapsed to a single row.

Note

Updated 2019-07-28.

See also

Examples

## character ==== groceries <- c(NA, NA, "milk", "eggs", "eggs", "veggies") collapseToString( groceries, unique = TRUE, sort = TRUE, removeNA = TRUE )
#> [1] "eggs, milk, veggies"
collapseToString( groceries, unique = FALSE, sort = FALSE, removeNA = 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 ==== datasets::iris %>% head() %>% collapseToString(sort = TRUE, unique = TRUE) %>% t()
#> [,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"