Concatenating N columns of text in R

前端 未结 2 426
我在风中等你
我在风中等你 2021-01-04 22:42

I have an arbitrary number of columns containing text data that have been assembled using the cbind() command, for example:

[1,] \"Text 1,1\" \"Text 1,2\" \"Te

2条回答
  •  無奈伤痛
    2021-01-04 23:27

    Just use paste with its collapse argument:

    R> row <- c("Text 1,1",  "Text 1,2", "Text 1,n")
    R> paste(row, collapse=" ")
    [1] "Text 1,1 Text 1,2 Text 1,n"
    R> 
    

    paste is vectorised, so you can feed it multiple arguments at once.

提交回复
热议问题