I'm trying to sort the strings inside the 'specs' column, but whenever I use str_sort (stringr), it successfully sorts the strings in 'specs' but also the entire column and does not preserve the row structure. The 'sorted' column is the result of the following code:
nest_use %>%
mutate(sorted = str_sort(specs))
nest days Date age specs no_specs sorted
1 595 86 2020:07:03 80 arlo, bird 2 arlo, bird
2 595 86 2020:08:05 80 tato, bird 2 arlo, bird
3 595 86 2020:08:22 80 arlo, unk 2 arlo, bird
4 595 86 2020:09:11 80 unk, glor 2 arlo, bird
5 595 86 2020:09:19 80 glor, unk 2 arlo, bird
6 595 86 2020:10:14 80 glor, unk 2 arlo, bird
7 595 86 2020:10:16 80 tado, arlo, glor 3 arlo, bird
8 595 86 2020:10:19 80 glor, unk 2 arlo, bird, glor
9 595 86 2020:10:20 80 unk, glor 2 arlo, bird, tado
10 595 86 2020:10:22 80 glor, arlo, bird 3 arlo, corvid
# ... with 93 more rows
What I would like to see is the following output as a data.frame where the strings in 'specs' are sorted and the order of rows is preserved:
nest days Date age specs no_specs sorted
<int> <int> <chr> <int> <chr> <dbl> <chr>
1 595 86 2020:07:03 80 arlo, bird 2 arlo, bird
2 595 86 2020:08:05 80 tato, bird 2 bird, tato
3 595 86 2020:08:22 80 arlo, unk 2 arlo, unk
4 595 86 2020:09:11 80 unk, glor 2 glor, unk
5 595 86 2020:09:19 80 glor, unk 2 glor, unk
6 595 86 2020:10:14 80 glor, unk 2 glor, unk
7 595 86 2020:10:16 80 tado, arlo, glor 3 arlo, glor, tado
8 595 86 2020:10:19 80 glor, unk 2 glor, unk
9 595 86 2020:10:20 80 unk, glor 2 glor, unk
10 595 86 2020:10:22 80 glor, arlo, bird 3 arlo, bird, glor
# ... with 93 more rows
I've searched for quite a while and have not quite found the solution for this issue.