gpt4 book ai didi

R 编程 : Automating Merge of Character Strings

转载 作者:行者123 更新时间:2023-12-04 06:23:27 24 4
gpt4 key购买 nike

我正在尝试使这里工作的一些系统自动化,专门用于根据调查数据生成报告。

假设我对 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")

最佳答案

paste(current_comments, collapse=" - ")

关于R 编程 : Automating Merge of Character Strings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3920704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com