I have a data frame, and one of the columns in the data frame contains a string of items separated by commas like this;
[1] "A, D, B, C"
[2] "D, A, B, C"
[3] "B, A, C, D"
etc...
Is there a way to sort these strings within themselves, so that I can get something like this?:
"A, B, C, D"
"A, B, C, D"
"A, B, C, D"
I am close with the following:
library(gtools)
df$col <- sapply(df$col , function (x)
mixedsort(strsplit(paste(x, collapse = ','), ',')[[1]]))
But this outputs the results as a list, so I can't do any manipulations in dplyr on the output (like group_by)