Here we are explaining how to write an R program to concatenate a vector. Here we are using a built-in function paste(), collapse() for this . Function paste() helps to concatenate vectors after converting to characters.The collapse() function helps to collapses a character vector of any length into a length 1 vector. The syntax of this method is like
paste0(…, collapse = NULL)
– where …(dots) indicates one or more R objects, to be converted to character vectors and collapse is an optional character string to separate the resultscollapse(x, sep = ““, width = Inf, last =”“)
– where x is the character vector to collapse, sep is the character string to separate the term. The maximum string width before truncating is indicated by width finally, the last is the last string used to separate the last two items.
Below are the steps used in the R program to concatenate a vector. In this R program, we directly give the values to built-in functions. And print the function result. Here we used variable A for assigning vector values. And variable B for holding the concatenated string. The string is concatenated by calling like B = paste(A, collapse = ““). Finally print the concatenated string.
A = c("Java", "Python", "Php") print(A)
##  "Java" "Python" "Php"
B = paste(A, collapse = "") print("Concatenation of the string:")
##  "Concatenation of the string:"
##  "JavaPythonPhp"