将特征向量折叠成R中的单个观察

时间:2015-03-26 06:52:50

标签: r text vector

如何将多值向量减少到单个观察?具体来说,处理文本。解决方案应该是可扩展的。

考虑:

col <- c("This is row 1", "AND THIS IS ROW 2", "Wow, and this is row 3!")

返回以下内容:

> col
[1] "This is row 1"           "AND THIS IS ROW 2"       "Wow, and this is row 3!"

所需解决方案如下所示:

> col
[1] "This is row 1 AND THIS IS ROW 2 Wow, and this is row 3!"

1 个答案:

答案 0 :(得分:3)

您正在寻找?paste

> paste(col, collapse = " ")
#[1] "This is row 1 AND THIS IS ROW 2 Wow, and this is row 3!"

在这种情况下,您希望将字符串折叠在一起并在它们之间添加空格。您还可以查看paste0