views:

59

answers:

1

Hi there,

I'm trying to automate some of the systems at work here specifically to do with report generation based on survey data.

Lets say i have 3 comments for 1 question.

current_comments <- c("too slow", "not fast enough", "bad speed")

Basically what i want to do is merge the comments into one string separated by a "-" too look like this

>current_comments
[1] "too slow - not fast enough - bad speed"

So that i can stick it into one cell for exporting.

I know that i can do this by using the paste function.

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

But from an automation standpoint how would i do this with a varying number of comments.

Sorry for a newbie question but this has had me stumped for the better part of a afternoon.

edit: as requested heres dput(head(clean_data, 10)) with the names and the questions changed

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")
+6  A: 

hi

paste(current_comments, collapse=" - ")
kohske
Cheers,I should really give up on this programming stuff :P
Cam B