I have the following dataframe:
library(tidyverse)
library(tibble)
data_frame <-
tribble(
~a, ~b,
"2,29,3,30,31,4,5,2,28,29,3,30,4,5", "x",
"12,13,14,15,18,19,20,12,13,14,15,18,19,20,21" , "y"
)
I want to create a new column to this dataframe, called c, that can show the strings in a
arranged in numerical ascending order. C should ideally look like the following:
library(tidyverse)
library(tibble)
data_frame <-
tribble(
~a, ~b, ~c,
"2,29,3,30,31,4,5,2,28,29,3,30,4,5", "x", "2,2,3,3,4,4,5,5,28,29,29,30,30,31"
"12,13,14,15,18,19,20,12,13,14,15,18,19,20,21" , "y", "12,12,13,13,14,14,15,15,18,18,19,19,20,20,21"
)
How can I achieve this? I have tried using str_sort
from the stringr
package, and also the mixedsort
function from the gtools
library. Thank you.