Sorting text column to the bottom for numeroalpha texts

Hi there
I tried in excel to sort them to the bottom or top for those with 240GENERAL, 240EXPIREDSTOCK, etc.
But, failed.
dplyr arrange() also failed to sort the way I need.
repex is pasted here.
I hope you will help in this.
thank you so much.
G

customer <- tibble::tribble(
                        ~customer,        ~StartDateTime,          ~EndDateTime, ~Consultant, ~ServicingDepartment, ~ServiceCode, ~ActualCharge,
                         "004537", "2023-02-23 00:00:00", "2023-02-23 00:00:00",        "sc",                   1L,   "material",         81.76,
                         "008195", "2023-02-27 00:00:00", "2023-02-27 00:00:00",        "sc",                   1L,   "material",         26.81,
                         "008195", "2023-03-28 00:00:00", "2023-03-28 00:00:00",        "sc",                   1L,   "material",        174.41,
                         "010895", "2023-01-24 00:00:00", "2023-01-24 00:00:00",        "sc",                   1L,   "material",       1528.78,
                         "010895", "2023-01-24 00:00:00", "2023-01-24 00:00:00",        "sc",                   2L,   "material",          1805,
                        "2409901", "2022-08-22 00:00:00", "2022-08-22 00:00:00",        "sc",                   1L,   "material",        765.04,
                        "2409980", "2022-08-16 00:00:00", "2022-08-16 00:00:00",        "sc",                   1L,   "material",        323.49,
                "240EXPIREDSTOCK", "2023-01-11 00:00:00", "2023-01-11 00:00:00",        "sc",                   1L,   "material",           735,
                "240EXPIREDSTOCK", "2023-02-10 00:00:00", "2023-02-10 00:00:00",        "sc",                   1L,   "material",           577,
                "240EXPIREDSTOCK", "2023-03-01 00:00:00", "2023-03-01 00:00:00",        "sc",                   2L,   "material",           336,
                "240EXPIREDSTOCK", "2023-01-11 00:00:00", "2023-01-11 00:00:00",        "sc",                   1L,   "material",           735,
                "240EXPIREDSTOCK", "2023-02-10 00:00:00", "2023-02-10 00:00:00",        "sc",                   1L,   "material",           577,
                "240EXPIREDSTOCK", "2023-03-01 00:00:00", "2023-03-01 00:00:00",        "sc",                   2L,   "material",           336,
                     "240GENERAL", "2022-07-01 00:00:00", "2022-07-01 00:00:00",        "sc",                   1L,   "material",           384,
                     "240GENERAL", "2022-07-14 00:00:00", "2022-07-14 00:00:00",        "sc",                   1L,   "material",          2379,
                     "240GENERAL", "2022-07-18 00:00:00", "2022-07-18 00:00:00",        "sc",                   1L,   "material",         50.64,
                     "240GENERAL", "2023-01-10 00:00:00", "2023-01-10 00:00:00",        "sc",                   1L,   "material",           968,
                     "240GENERAL", "2023-01-18 00:00:00", "2023-01-18 00:00:00",        "sc",                   1L,   "material",           288,
              "240OPERATINGSUITE", "2023-02-28 00:00:00", "2023-02-28 00:00:00",        "sc",                   1L,   "material",        142.66,
              "240OPERATINGSUITE", "2023-02-28 00:00:00", "2023-02-28 00:00:00",        "sc",                   2L,   "material",         550.5,
                 "240OUTPATIENTS", "2023-02-20 00:00:00", "2023-02-20 00:00:00",        "sc",                   1L,   "material",        738.78,
                        "2410024", "2023-01-19 00:00:00", "2023-01-19 00:00:00",        "sc",                   1L,   "material",         91.41,
                        "2410461", "2023-02-25 00:00:00", "2023-02-25 00:00:00",        "sc",                   1L,   "material",         176.7,
                         "241066", "2023-02-27 00:00:00", "2023-02-27 00:00:00",        "sc",                   1L,   "material",        118.64,
                         "241066", "2023-02-27 00:00:00", "2023-02-27 00:00:00",        "sc",                   2L,   "material",         624.6,
                        "2412517", "2023-03-10 00:00:00", "2023-03-10 00:00:00",        "sc",                   1L,   "material",         28.51,
                        "2412848", "2023-02-03 00:00:00", "2023-02-03 00:00:00",        "sc",                   1L,   "material",        106.75,
                        "2413666", "2023-02-15 00:00:00", "2023-02-15 00:00:00",        "sc",                   1L,   "material",        564.34,
                        "2413787", "2023-03-29 00:00:00", "2023-03-29 00:00:00",        "sc",                   1L,   "material",         82.08
              )

customer
#> # A tibble: 29 × 7
#>    customer StartDateTime EndDateTime Consultant ServicingDepartment ServiceCode
#>    <chr>    <chr>         <chr>       <chr>                    <int> <chr>      
#>  1 004537   2023-02-23 0… 2023-02-23… sc                           1 material   
#>  2 008195   2023-02-27 0… 2023-02-27… sc                           1 material   
#>  3 008195   2023-03-28 0… 2023-03-28… sc                           1 material   
#>  4 010895   2023-01-24 0… 2023-01-24… sc                           1 material   
#>  5 010895   2023-01-24 0… 2023-01-24… sc                           2 material   
#>  6 2409901  2022-08-22 0… 2022-08-22… sc                           1 material   
#>  7 2409980  2022-08-16 0… 2022-08-16… sc                           1 material   
#>  8 240EXPI… 2023-01-11 0… 2023-01-11… sc                           1 material   
#>  9 240EXPI… 2023-02-10 0… 2023-02-10… sc                           1 material   
#> 10 240EXPI… 2023-03-01 0… 2023-03-01… sc                           2 material   
#> # ℹ 19 more rows
#> # ℹ 1 more variable: ActualCharge <dbl>

customer.outcome <- tibble::tribble(
                                ~customer,        ~StartDateTime,          ~EndDateTime, ~Consultant, ~ServicingDepartment, ~ServiceCode, ~ActualCharge,
                                 "004537", "2023-02-23 00:00:00", "2023-02-23 00:00:00",        "sc",                   1L,   "material",         81.76,
                                 "008195", "2023-02-27 00:00:00", "2023-02-27 00:00:00",        "sc",                   1L,   "material",         26.81,
                                 "008195", "2023-03-28 00:00:00", "2023-03-28 00:00:00",        "sc",                   1L,   "material",        174.41,
                                 "010895", "2023-01-24 00:00:00", "2023-01-24 00:00:00",        "sc",                   1L,   "material",       1528.78,
                                 "010895", "2023-01-24 00:00:00", "2023-01-24 00:00:00",        "sc",                   2L,   "material",          1805,
                                "2409901", "2022-08-22 00:00:00", "2022-08-22 00:00:00",        "sc",                   1L,   "material",        765.04,
                                "2409980", "2022-08-16 00:00:00", "2022-08-16 00:00:00",        "sc",                   1L,   "material",        323.49,
                                "2410024", "2023-01-19 00:00:00", "2023-01-19 00:00:00",        "sc",                   1L,   "material",         91.41,
                                "2410461", "2023-02-25 00:00:00", "2023-02-25 00:00:00",        "sc",                   1L,   "material",         176.7,
                                 "241066", "2023-02-27 00:00:00", "2023-02-27 00:00:00",        "sc",                   1L,   "material",        118.64,
                                 "241066", "2023-02-27 00:00:00", "2023-02-27 00:00:00",        "sc",                   2L,   "material",         624.6,
                                "2412517", "2023-03-10 00:00:00", "2023-03-10 00:00:00",        "sc",                   1L,   "material",         28.51,
                                "2412848", "2023-02-03 00:00:00", "2023-02-03 00:00:00",        "sc",                   1L,   "material",        106.75,
                                "2413666", "2023-02-15 00:00:00", "2023-02-15 00:00:00",        "sc",                   1L,   "material",        564.34,
                                "2413787", "2023-03-29 00:00:00", "2023-03-29 00:00:00",        "sc",                   1L,   "material",         82.08,
                        "240EXPIREDSTOCK", "2023-01-11 00:00:00", "2023-01-11 00:00:00",        "sc",                   1L,   "material",           735,
                        "240EXPIREDSTOCK", "2023-02-10 00:00:00", "2023-02-10 00:00:00",        "sc",                   1L,   "material",           577,
                        "240EXPIREDSTOCK", "2023-03-01 00:00:00", "2023-03-01 00:00:00",        "sc",                   2L,   "material",           336,
                        "240EXPIREDSTOCK", "2023-01-11 00:00:00", "2023-01-11 00:00:00",        "sc",                   1L,   "material",           735,
                        "240EXPIREDSTOCK", "2023-02-10 00:00:00", "2023-02-10 00:00:00",        "sc",                   1L,   "material",           577,
                        "240EXPIREDSTOCK", "2023-03-01 00:00:00", "2023-03-01 00:00:00",        "sc",                   2L,   "material",           336,
                             "240GENERAL", "2022-07-01 00:00:00", "2022-07-01 00:00:00",        "sc",                   1L,   "material",           384,
                             "240GENERAL", "2022-07-14 00:00:00", "2022-07-14 00:00:00",        "sc",                   1L,   "material",          2379,
                             "240GENERAL", "2022-07-18 00:00:00", "2022-07-18 00:00:00",        "sc",                   1L,   "material",         50.64,
                             "240GENERAL", "2023-01-10 00:00:00", "2023-01-10 00:00:00",        "sc",                   1L,   "material",           968,
                             "240GENERAL", "2023-01-18 00:00:00", "2023-01-18 00:00:00",        "sc",                   1L,   "material",           288,
                      "240OPERATINGSUITE", "2023-02-28 00:00:00", "2023-02-28 00:00:00",        "sc",                   1L,   "material",        142.66,
                      "240OPERATINGSUITE", "2023-02-28 00:00:00", "2023-02-28 00:00:00",        "sc",                   2L,   "material",         550.5,
                         "240OUTPATIENTS", "2023-02-20 00:00:00", "2023-02-20 00:00:00",        "sc",                   1L,   "material",        738.78
                      )
customer.outcome
#> # A tibble: 29 × 7
#>    customer StartDateTime EndDateTime Consultant ServicingDepartment ServiceCode
#>    <chr>    <chr>         <chr>       <chr>                    <int> <chr>      
#>  1 004537   2023-02-23 0… 2023-02-23… sc                           1 material   
#>  2 008195   2023-02-27 0… 2023-02-27… sc                           1 material   
#>  3 008195   2023-03-28 0… 2023-03-28… sc                           1 material   
#>  4 010895   2023-01-24 0… 2023-01-24… sc                           1 material   
#>  5 010895   2023-01-24 0… 2023-01-24… sc                           2 material   
#>  6 2409901  2022-08-22 0… 2022-08-22… sc                           1 material   
#>  7 2409980  2022-08-16 0… 2022-08-16… sc                           1 material   
#>  8 2410024  2023-01-19 0… 2023-01-19… sc                           1 material   
#>  9 2410461  2023-02-25 0… 2023-02-25… sc                           1 material   
#> 10 241066   2023-02-27 0… 2023-02-27… sc                           1 material   
#> # ℹ 19 more rows
#> # ℹ 1 more variable: ActualCharge <dbl>

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
customer %>% 
  arrange(customer) %>% 
  View()

Created on 2023-07-17 with reprex v2.0.2

How about this?

customer %>% 
  arrange(as.numeric(customer)) %>% 
  print(n = 29)

1 Like

That works.
Excellent!
Thank you so much.
G

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.