Reputation: 107
I have a dataframe named df
with only a column named Reviews
:
Reviews
"Good, Excellent, I love this!"
"This is great, quality is good"
"Excellent service and quality, Good, amazing"
How could I convert the column into a single list as follows?:
Reviews
"Good, Excellent, I love this!", "This is great, quality is good", "Excellent service and quality, Good, amazing"
I tried unnest
but it is not suitable in this case as it returns Error in UseMethod("unnest"): no applicable method for 'unnest' applied to an object of class "list"
Upvotes: 2
Views: 129
Reputation: 78917
Update: OP Request: We can do it this way:
df %>%
mutate(Reviews = paste0('"',Reviews,'"')) %>%
summarise(Reviews = toString(Reviews))
Reviews
1 "Good, Excellent, I love this!", "This is great, quality is good", "Excellent service and quality, Good, amazing"
>
First answer:
We could use toString
with summarise
library(dplyr)
df %>%
summarise(Reviews = toString(Reviews))
1 Good, Excellent, I love this!, This is great, quality is good, Excellent service and quality, Good, amazing
>
Upvotes: 2
Reputation: 4425
Try this
paste0(df$Reviews , collapse = ", ")
[1] "Good, Excellent, I love this!, This is great, quality is good, Excellent service and quality, Good, amazing"
Upvotes: 2