R编程:自动化字符串的合并

Cam*_*m B 2 string automation r character

我正在尝试自动化这里的一些系统,特别是基于调查数据生成报告.

假设我对1个问题有3条评论.

current_comments <- c("too slow", "not fast enough", "bad speed")
Run Code Online (Sandbox Code Playgroud)

基本上我想要做的是将注释合并到一个由" - "分隔的字符串中,看起来像这样

>current_comments
[1] "too slow - not fast enough - bad speed"
Run Code Online (Sandbox Code Playgroud)

这样我就可以将它粘在一个单元格中进行导出.

我知道我可以通过使用粘贴功能来实现这一点.

> paste(current_comments[1], " - ", current_comments[2], " - ", current_comments[3])
[1] "too slow  -  not fast enough  -  bad speed"
Run Code Online (Sandbox Code Playgroud)

但从自动化角度来看,如何通过不同数量的评论来做到这一点.

很抱歉有一个新手问题,但这让我在下午的大部分时间里难以接受.

编辑:按照要求继续dput(head(clean_data, 10))使用名称和问题进行更改

ture(list(res_qnumber = 1:10, res_ID = c(44024431L, 44024431L, 
44024431L, 44024431L, 44024431L, 44024431L, 44024431L, 44024431L, 
44024431L, 44024431L), res_name = c("name1", "name1", 
"name1", "name1", "name1", "name1", "name1", 
"name1", "name1", "name1"), res_pos = c("NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA"), res_ceo = c(FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
), res_qtype = c("standard", "standard", "standard", "standard", 
"standard", "standard", "standard", "standard", "standard", "standard"
), res_qtext = c("Question1", 
"Question2", 
"Question3", 
"Question4", 
"Question5", 
"Question6", 
"Question7", 
"Question8", 
"Question9"
), res_response = c("2", "5", "5", "5", "5", "5", "5", "5", "5", 
"5"), res_comment = c("too slow", NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_), res_scale = c("scale1", "scale2", 
"scale3", "scale4", "scale5", "scale6", "scale7", "scale8", "scale9", 
"scale10")), .Names = c("res_qnumber", "res_ID", "res_name", 
"res_pos", "res_ceo", "res_qtype", "res_qtext", "res_response", 
"res_comment", "res_scale"), row.names = c(NA, 10L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

koh*_*ske 7

paste(current_comments, collapse=" - ")
Run Code Online (Sandbox Code Playgroud)