How to sort a character vector where elements contain letters and numbers in R? The Next CEO of Stack OverflowOrder colnames by char + numberOrder data.frame after numbers within character column in ROrdering character values while preserving number orderSorting A Character Dataframe According to desired waysort strings by numbers inside themArrange column in data framehow to group rows without ordering?Sorting character vector containing semantic versionsHow to sort by Library of Congress Classification (LCC) number in RSort a dataframe based on a character column containing letters followed by numbers in RHow do I sort a list of dictionaries by a value of the dictionary?How do I sort a dictionary by value?How do I sort an NSMutableArray with custom objects in it?How to sort a dataframe by multiple column(s)?Java Array Sort descending?Sorting an array in descending order in RubyHow to Sort Multi-dimensional Array by Value?How to Sort a List<T> by a property in the objectGrouping functions (tapply, by, aggregate) and the *apply familySwift Beta performance: sorting arrays

Is it okay to store user locations?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Why here is plural "We went to the movies last night."

Implement the Thanos sorting algorithm

Why is there a PLL in CPU?

What do "high sea" and "carry" mean in this sentence?

How can I open an app using Terminal?

How to make a variable always equal to the result of some calculations?

How do scammers retract money, while you can’t?

Increase performance creating Mandelbrot set in python

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables

How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?

Does the Brexit deal have to be agreed by both Houses?

Trouble understanding the speech of overseas colleagues

Apart from "berlinern", do any other German dialects have a corresponding verb?

Term for the "extreme-extension" version of a straw man fallacy?

Does it take more energy to get to Venus or to Mars?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

How do I construct this japanese bowl?

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

Opposite of a diet

What can we do to stop prior company from asking us questions?

Why did we only see the N-1 starfighters in one film?

What does this shorthand mean?



How to sort a character vector where elements contain letters and numbers in R?



The Next CEO of Stack OverflowOrder colnames by char + numberOrder data.frame after numbers within character column in ROrdering character values while preserving number orderSorting A Character Dataframe According to desired waysort strings by numbers inside themArrange column in data framehow to group rows without ordering?Sorting character vector containing semantic versionsHow to sort by Library of Congress Classification (LCC) number in RSort a dataframe based on a character column containing letters followed by numbers in RHow do I sort a list of dictionaries by a value of the dictionary?How do I sort a dictionary by value?How do I sort an NSMutableArray with custom objects in it?How to sort a dataframe by multiple column(s)?Java Array Sort descending?Sorting an array in descending order in RubyHow to Sort Multi-dimensional Array by Value?How to Sort a List<T> by a property in the objectGrouping functions (tapply, by, aggregate) and the *apply familySwift Beta performance: sorting arrays










32















I have a character array



cf <- c("V440","V457","V116","V327","V446","V108",
"V155","V217","V120","V51","V477")


I would like to sort it in descending order so that I will have an output like this:



V51
V108
V116
V120
V155
V217
V327
V440
V446
V457
V477


I have tried sort.list() like this



cf[sort.list(cf)]


and got this answer:



[1] "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477" "V51" 


and also tried order() and got same result.



Can someone help me please










share|improve this question




























    32















    I have a character array



    cf <- c("V440","V457","V116","V327","V446","V108",
    "V155","V217","V120","V51","V477")


    I would like to sort it in descending order so that I will have an output like this:



    V51
    V108
    V116
    V120
    V155
    V217
    V327
    V440
    V446
    V457
    V477


    I have tried sort.list() like this



    cf[sort.list(cf)]


    and got this answer:



    [1] "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477" "V51" 


    and also tried order() and got same result.



    Can someone help me please










    share|improve this question


























      32












      32








      32


      15






      I have a character array



      cf <- c("V440","V457","V116","V327","V446","V108",
      "V155","V217","V120","V51","V477")


      I would like to sort it in descending order so that I will have an output like this:



      V51
      V108
      V116
      V120
      V155
      V217
      V327
      V440
      V446
      V457
      V477


      I have tried sort.list() like this



      cf[sort.list(cf)]


      and got this answer:



      [1] "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477" "V51" 


      and also tried order() and got same result.



      Can someone help me please










      share|improve this question
















      I have a character array



      cf <- c("V440","V457","V116","V327","V446","V108",
      "V155","V217","V120","V51","V477")


      I would like to sort it in descending order so that I will have an output like this:



      V51
      V108
      V116
      V120
      V155
      V217
      V327
      V440
      V446
      V457
      V477


      I have tried sort.list() like this



      cf[sort.list(cf)]


      and got this answer:



      [1] "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477" "V51" 


      and also tried order() and got same result.



      Can someone help me please







      r sorting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 25 at 7:47









      Old Pro

      15.3k23970




      15.3k23970










      asked Jul 8 '13 at 16:19









      rinzy kutexrinzy kutex

      5421512




      5421512






















          6 Answers
          6






          active

          oldest

          votes


















          40














          Try mixedsort from the "gtools" package:



          > # install.packages("gtools") ## Uncomment if not already installed
          > library(gtools)
          > mixedsort(cf)
          [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"



          If you don't want to use mixedsort (not sure why one wouldn't), and if your vector has a pretty consistent pattern (eg letters followed by numbers), you can also probably try something like this. (Note: Relatively untested.)



          newvec <- c("V440", "V457", "V116", "V327", "V446", "V108", "V155", 
          "V217", "V120", "V51", "V477", "B22", "A10", "Z01")

          newvec[order(gsub("([A-Z]+)([0-9]+)", "\1", newvec),
          as.numeric(gsub("([A-Z]+)([0-9]+)", "\2", newvec)))]
          # [1] "A10" "B22" "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440"
          # [11] "V446" "V457" "V477" "Z01"





          share|improve this answer
































            35














            Plenty of right answers here, this is another way, just for fun.



            cf[order(nchar(cf), cf)]
            # [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





            share|improve this answer






























              8














              One more solution in a line of code using str_sortfunction (from the stringr packg.)



              # install.packages("stringr") ## Uncomment if not already installed
              library(stringr)


              str_sort(cf, numeric = TRUE)



              [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





              share|improve this answer


















              • 1





                this is great..

                – FMM
                Oct 1 '18 at 17:21











              • thanks! happy to help.

                – JDie
                Nov 15 '18 at 18:26


















              5














              Just scrape off the preceding "V" character to build a sorting vector. No additional fancy tools required.



              vals <- as.numeric(gsub("V","", cf))
              cf[order(vals)]

              [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446"
              [10] "V457" "V477"





              share|improve this answer






























                3














                R correctly orders strings alphabetically, that is why you get that result.



                Aside from @Ananda very good answer, if you want to use base R you can use strsplit to remove the "V" from each string and then use as.numeric to cast the strings to integers:



                vals <- as.numeric(sapply(cf, FUN=function(x)strsplit(x, "V")[[1]][2]))


                Now you can sort your strings using vals



                cf[order(vals)]





                share|improve this answer






























                  1














                  Here's a base approach utilizing names and sort (Ananda's was pretty slick):



                  cf <- c("V440","V457","V116","V327","V446","V108",
                  "V155","V217","V120","V51","V477")

                  cf2 <- as.numeric(gsub("[^[:digit:]]", "", cf))
                  names(cf2) <- seq_along(cf2)
                  cf[as.numeric(names(sort(cf2)))]

                  ## > cf[as.numeric(names(sort(cf2)))]
                  ## [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327"
                  ## [8] "V440" "V446" "V457" "V477"





                  share|improve this answer























                    Your Answer






                    StackExchange.ifUsing("editor", function ()
                    StackExchange.using("externalEditor", function ()
                    StackExchange.using("snippets", function ()
                    StackExchange.snippets.init();
                    );
                    );
                    , "code-snippets");

                    StackExchange.ready(function()
                    var channelOptions =
                    tags: "".split(" "),
                    id: "1"
                    ;
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function()
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled)
                    StackExchange.using("snippets", function()
                    createEditor();
                    );

                    else
                    createEditor();

                    );

                    function createEditor()
                    StackExchange.prepareEditor(
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader:
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    ,
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    );



                    );













                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17531403%2fhow-to-sort-a-character-vector-where-elements-contain-letters-and-numbers-in-r%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown

























                    6 Answers
                    6






                    active

                    oldest

                    votes








                    6 Answers
                    6






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    40














                    Try mixedsort from the "gtools" package:



                    > # install.packages("gtools") ## Uncomment if not already installed
                    > library(gtools)
                    > mixedsort(cf)
                    [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"



                    If you don't want to use mixedsort (not sure why one wouldn't), and if your vector has a pretty consistent pattern (eg letters followed by numbers), you can also probably try something like this. (Note: Relatively untested.)



                    newvec <- c("V440", "V457", "V116", "V327", "V446", "V108", "V155", 
                    "V217", "V120", "V51", "V477", "B22", "A10", "Z01")

                    newvec[order(gsub("([A-Z]+)([0-9]+)", "\1", newvec),
                    as.numeric(gsub("([A-Z]+)([0-9]+)", "\2", newvec)))]
                    # [1] "A10" "B22" "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440"
                    # [11] "V446" "V457" "V477" "Z01"





                    share|improve this answer





























                      40














                      Try mixedsort from the "gtools" package:



                      > # install.packages("gtools") ## Uncomment if not already installed
                      > library(gtools)
                      > mixedsort(cf)
                      [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"



                      If you don't want to use mixedsort (not sure why one wouldn't), and if your vector has a pretty consistent pattern (eg letters followed by numbers), you can also probably try something like this. (Note: Relatively untested.)



                      newvec <- c("V440", "V457", "V116", "V327", "V446", "V108", "V155", 
                      "V217", "V120", "V51", "V477", "B22", "A10", "Z01")

                      newvec[order(gsub("([A-Z]+)([0-9]+)", "\1", newvec),
                      as.numeric(gsub("([A-Z]+)([0-9]+)", "\2", newvec)))]
                      # [1] "A10" "B22" "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440"
                      # [11] "V446" "V457" "V477" "Z01"





                      share|improve this answer



























                        40












                        40








                        40







                        Try mixedsort from the "gtools" package:



                        > # install.packages("gtools") ## Uncomment if not already installed
                        > library(gtools)
                        > mixedsort(cf)
                        [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"



                        If you don't want to use mixedsort (not sure why one wouldn't), and if your vector has a pretty consistent pattern (eg letters followed by numbers), you can also probably try something like this. (Note: Relatively untested.)



                        newvec <- c("V440", "V457", "V116", "V327", "V446", "V108", "V155", 
                        "V217", "V120", "V51", "V477", "B22", "A10", "Z01")

                        newvec[order(gsub("([A-Z]+)([0-9]+)", "\1", newvec),
                        as.numeric(gsub("([A-Z]+)([0-9]+)", "\2", newvec)))]
                        # [1] "A10" "B22" "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440"
                        # [11] "V446" "V457" "V477" "Z01"





                        share|improve this answer















                        Try mixedsort from the "gtools" package:



                        > # install.packages("gtools") ## Uncomment if not already installed
                        > library(gtools)
                        > mixedsort(cf)
                        [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"



                        If you don't want to use mixedsort (not sure why one wouldn't), and if your vector has a pretty consistent pattern (eg letters followed by numbers), you can also probably try something like this. (Note: Relatively untested.)



                        newvec <- c("V440", "V457", "V116", "V327", "V446", "V108", "V155", 
                        "V217", "V120", "V51", "V477", "B22", "A10", "Z01")

                        newvec[order(gsub("([A-Z]+)([0-9]+)", "\1", newvec),
                        as.numeric(gsub("([A-Z]+)([0-9]+)", "\2", newvec)))]
                        # [1] "A10" "B22" "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440"
                        # [11] "V446" "V457" "V477" "Z01"






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jul 8 '13 at 16:42

























                        answered Jul 8 '13 at 16:21









                        A5C1D2H2I1M1N2O1R2T1A5C1D2H2I1M1N2O1R2T1

                        154k19291384




                        154k19291384























                            35














                            Plenty of right answers here, this is another way, just for fun.



                            cf[order(nchar(cf), cf)]
                            # [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





                            share|improve this answer



























                              35














                              Plenty of right answers here, this is another way, just for fun.



                              cf[order(nchar(cf), cf)]
                              # [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





                              share|improve this answer

























                                35












                                35








                                35







                                Plenty of right answers here, this is another way, just for fun.



                                cf[order(nchar(cf), cf)]
                                # [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





                                share|improve this answer













                                Plenty of right answers here, this is another way, just for fun.



                                cf[order(nchar(cf), cf)]
                                # [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 8 '13 at 16:35









                                Matthew PlourdeMatthew Plourde

                                35.5k469101




                                35.5k469101





















                                    8














                                    One more solution in a line of code using str_sortfunction (from the stringr packg.)



                                    # install.packages("stringr") ## Uncomment if not already installed
                                    library(stringr)


                                    str_sort(cf, numeric = TRUE)



                                    [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





                                    share|improve this answer


















                                    • 1





                                      this is great..

                                      – FMM
                                      Oct 1 '18 at 17:21











                                    • thanks! happy to help.

                                      – JDie
                                      Nov 15 '18 at 18:26















                                    8














                                    One more solution in a line of code using str_sortfunction (from the stringr packg.)



                                    # install.packages("stringr") ## Uncomment if not already installed
                                    library(stringr)


                                    str_sort(cf, numeric = TRUE)



                                    [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





                                    share|improve this answer


















                                    • 1





                                      this is great..

                                      – FMM
                                      Oct 1 '18 at 17:21











                                    • thanks! happy to help.

                                      – JDie
                                      Nov 15 '18 at 18:26













                                    8












                                    8








                                    8







                                    One more solution in a line of code using str_sortfunction (from the stringr packg.)



                                    # install.packages("stringr") ## Uncomment if not already installed
                                    library(stringr)


                                    str_sort(cf, numeric = TRUE)



                                    [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"





                                    share|improve this answer













                                    One more solution in a line of code using str_sortfunction (from the stringr packg.)



                                    # install.packages("stringr") ## Uncomment if not already installed
                                    library(stringr)


                                    str_sort(cf, numeric = TRUE)



                                    [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446" "V457" "V477"






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jul 29 '18 at 9:48









                                    JDieJDie

                                    9612




                                    9612







                                    • 1





                                      this is great..

                                      – FMM
                                      Oct 1 '18 at 17:21











                                    • thanks! happy to help.

                                      – JDie
                                      Nov 15 '18 at 18:26












                                    • 1





                                      this is great..

                                      – FMM
                                      Oct 1 '18 at 17:21











                                    • thanks! happy to help.

                                      – JDie
                                      Nov 15 '18 at 18:26







                                    1




                                    1





                                    this is great..

                                    – FMM
                                    Oct 1 '18 at 17:21





                                    this is great..

                                    – FMM
                                    Oct 1 '18 at 17:21













                                    thanks! happy to help.

                                    – JDie
                                    Nov 15 '18 at 18:26





                                    thanks! happy to help.

                                    – JDie
                                    Nov 15 '18 at 18:26











                                    5














                                    Just scrape off the preceding "V" character to build a sorting vector. No additional fancy tools required.



                                    vals <- as.numeric(gsub("V","", cf))
                                    cf[order(vals)]

                                    [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446"
                                    [10] "V457" "V477"





                                    share|improve this answer



























                                      5














                                      Just scrape off the preceding "V" character to build a sorting vector. No additional fancy tools required.



                                      vals <- as.numeric(gsub("V","", cf))
                                      cf[order(vals)]

                                      [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446"
                                      [10] "V457" "V477"





                                      share|improve this answer

























                                        5












                                        5








                                        5







                                        Just scrape off the preceding "V" character to build a sorting vector. No additional fancy tools required.



                                        vals <- as.numeric(gsub("V","", cf))
                                        cf[order(vals)]

                                        [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446"
                                        [10] "V457" "V477"





                                        share|improve this answer













                                        Just scrape off the preceding "V" character to build a sorting vector. No additional fancy tools required.



                                        vals <- as.numeric(gsub("V","", cf))
                                        cf[order(vals)]

                                        [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327" "V440" "V446"
                                        [10] "V457" "V477"






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jul 8 '13 at 16:24









                                        David MarxDavid Marx

                                        5,15012449




                                        5,15012449





















                                            3














                                            R correctly orders strings alphabetically, that is why you get that result.



                                            Aside from @Ananda very good answer, if you want to use base R you can use strsplit to remove the "V" from each string and then use as.numeric to cast the strings to integers:



                                            vals <- as.numeric(sapply(cf, FUN=function(x)strsplit(x, "V")[[1]][2]))


                                            Now you can sort your strings using vals



                                            cf[order(vals)]





                                            share|improve this answer



























                                              3














                                              R correctly orders strings alphabetically, that is why you get that result.



                                              Aside from @Ananda very good answer, if you want to use base R you can use strsplit to remove the "V" from each string and then use as.numeric to cast the strings to integers:



                                              vals <- as.numeric(sapply(cf, FUN=function(x)strsplit(x, "V")[[1]][2]))


                                              Now you can sort your strings using vals



                                              cf[order(vals)]





                                              share|improve this answer

























                                                3












                                                3








                                                3







                                                R correctly orders strings alphabetically, that is why you get that result.



                                                Aside from @Ananda very good answer, if you want to use base R you can use strsplit to remove the "V" from each string and then use as.numeric to cast the strings to integers:



                                                vals <- as.numeric(sapply(cf, FUN=function(x)strsplit(x, "V")[[1]][2]))


                                                Now you can sort your strings using vals



                                                cf[order(vals)]





                                                share|improve this answer













                                                R correctly orders strings alphabetically, that is why you get that result.



                                                Aside from @Ananda very good answer, if you want to use base R you can use strsplit to remove the "V" from each string and then use as.numeric to cast the strings to integers:



                                                vals <- as.numeric(sapply(cf, FUN=function(x)strsplit(x, "V")[[1]][2]))


                                                Now you can sort your strings using vals



                                                cf[order(vals)]






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jul 8 '13 at 16:25









                                                niconico

                                                39.9k1269102




                                                39.9k1269102





















                                                    1














                                                    Here's a base approach utilizing names and sort (Ananda's was pretty slick):



                                                    cf <- c("V440","V457","V116","V327","V446","V108",
                                                    "V155","V217","V120","V51","V477")

                                                    cf2 <- as.numeric(gsub("[^[:digit:]]", "", cf))
                                                    names(cf2) <- seq_along(cf2)
                                                    cf[as.numeric(names(sort(cf2)))]

                                                    ## > cf[as.numeric(names(sort(cf2)))]
                                                    ## [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327"
                                                    ## [8] "V440" "V446" "V457" "V477"





                                                    share|improve this answer



























                                                      1














                                                      Here's a base approach utilizing names and sort (Ananda's was pretty slick):



                                                      cf <- c("V440","V457","V116","V327","V446","V108",
                                                      "V155","V217","V120","V51","V477")

                                                      cf2 <- as.numeric(gsub("[^[:digit:]]", "", cf))
                                                      names(cf2) <- seq_along(cf2)
                                                      cf[as.numeric(names(sort(cf2)))]

                                                      ## > cf[as.numeric(names(sort(cf2)))]
                                                      ## [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327"
                                                      ## [8] "V440" "V446" "V457" "V477"





                                                      share|improve this answer

























                                                        1












                                                        1








                                                        1







                                                        Here's a base approach utilizing names and sort (Ananda's was pretty slick):



                                                        cf <- c("V440","V457","V116","V327","V446","V108",
                                                        "V155","V217","V120","V51","V477")

                                                        cf2 <- as.numeric(gsub("[^[:digit:]]", "", cf))
                                                        names(cf2) <- seq_along(cf2)
                                                        cf[as.numeric(names(sort(cf2)))]

                                                        ## > cf[as.numeric(names(sort(cf2)))]
                                                        ## [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327"
                                                        ## [8] "V440" "V446" "V457" "V477"





                                                        share|improve this answer













                                                        Here's a base approach utilizing names and sort (Ananda's was pretty slick):



                                                        cf <- c("V440","V457","V116","V327","V446","V108",
                                                        "V155","V217","V120","V51","V477")

                                                        cf2 <- as.numeric(gsub("[^[:digit:]]", "", cf))
                                                        names(cf2) <- seq_along(cf2)
                                                        cf[as.numeric(names(sort(cf2)))]

                                                        ## > cf[as.numeric(names(sort(cf2)))]
                                                        ## [1] "V51" "V108" "V116" "V120" "V155" "V217" "V327"
                                                        ## [8] "V440" "V446" "V457" "V477"






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Jul 8 '13 at 16:29









                                                        Tyler RinkerTyler Rinker

                                                        65.2k42234412




                                                        65.2k42234412



























                                                            draft saved

                                                            draft discarded
















































                                                            Thanks for contributing an answer to Stack Overflow!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid


                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.

                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17531403%2fhow-to-sort-a-character-vector-where-elements-contain-letters-and-numbers-in-r%23new-answer', 'question_page');

                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                                            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                                                            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme