我正在尝试自动化这里工作的一些系统,专门用于根据调查数据生成报告。
假设我对 1 个问题有 3 条评论。
current_comments <- c("too slow", "not fast enough", "bad speed")
基本上我想要做的是将注释合并到一个由“-”分隔的字符串中,看起来像这样
>current_comments
[1] "too slow - not fast enough - bad speed"
这样我就可以将它粘贴到一个单元格中进行导出。
我知道我可以通过使用粘贴功能来做到这一点。
> paste(current_comments[1], " - ", current_comments[2], " - ", current_comments[3])
[1] "too slow - not fast enough - bad speed"
但从自动化的角度来看,我将如何通过不同数量的评论来做到这一点。
很抱歉提出了一个新手问题,但这让我困惑了一个下午的大部分时间。
编辑:按照要求这里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")