Learn R Programming

udpipe (version 0.8.11)

txt_paste: Concatenate strings with options how to handle missing data

Description

NA friendly version for concatenating string

Usage

txt_paste(..., collapse = " ", na.rm = FALSE)

Value

a character vector

Arguments

...

character vectors

collapse

a character string to be used to paste the vectors together. Defaults to a space: ' '.

na.rm

logical, if set to TRUE, will replace NA with ''. If set to FALSE, will have a resulting value of NA if at least one element is NA, in a similar spirit as mean. Defaults to FALSE.

See Also

Examples

Run this code
x <- c(1, 2, 3, NA, NA)
y <- c("a", "b", "c", NA, "OK")
paste(x, y, sep = "-")
txt_paste(x, y, collapse = "-", na.rm = TRUE)
txt_paste(x, y, collapse = "-", na.rm = FALSE)

x <- c(NA, "a", "b")
y <- c("1", "2", NA)
z <- c("-", "*", NA)
txt_paste(x, y, z, collapse = "", na.rm = TRUE)
txt_paste(x, y, z, "_____", collapse = "", na.rm = TRUE)
txt_paste(x, y, z, "_____", collapse = "", na.rm = FALSE)

Run the code above in your browser using DataLab