I'm doing a simple operation using dplyr in R and got 'expecting single value' error
test <- data.frame(a=rep("item",3),b=c("step1","step2","step3"))
test%>%group_by(a)%>%(summarize(seq=paste0(b))
I've seen similar threads but those use cases were more complex, and I couldn't figure out why these 2 lines don't work.
Since you only have one group ("item") the paste0
will get a vector of the three items in b
as input and will return a vector of three strings, but your summarize is expecting a single value (since there is only one group). You need to collapse
the paste0
to a single string like this:
library(dplyr)
test <- data.frame(a=rep("item",3), b=c("step1","step2","step3"))
test %>% group_by(a) %>% summarize(seq = paste0(b, collapse = ""))