如何将多值向量减少到单个观察?具体来说,处理文本。解决方案应该是可扩展的。
考虑:
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!"
答案 0 :(得分:3)
您正在寻找?paste
:
> paste(col, collapse = " ")
#[1] "This is row 1 AND THIS IS ROW 2 Wow, and this is row 3!"
在这种情况下,您希望将字符串折叠在一起并在它们之间添加空格。您还可以查看paste0
。