0

Is there a way to convert all strings into one. For example

asds <- c("as","asd","sdff")
asds
[1] "as"   "asd"  "sdff"

Expected output

asds
'as asd sdff'

I just tried with below code but getting the error

> asds <- c("as","asd","sdff")
> paste: paste(asds, collapse=" ")
Error in paste:paste(asds, collapse = " ") : NA/NaN argument
In addition: Warning message:
NAs introduced by coercion 
user11740857
  • 502
  • 3
  • 10

1 Answers1

1

Update: comment of OP:

wrap toString around:

toString(glue_collapse(asds, sep = " "))

Alternative use stri_join from stringi package

library(stringi)
stri_join(asds, collapse=' ')

# output:
[1] "as asd sdff"

First answer:

We could use glue_collapse

glue_collapse(asds, sep = " ")

output:

as asd sdff
TarJae
  • 72,363
  • 6
  • 19
  • 66