Main navigation

Please help us to improve R-exercises:

Reader Interactions


    • Hello Santi !!! Thanks for your comment.
      You will need 2 packages: stringr and stringi. I already added it to the solution.

      • Hello!

        Not necessarily:

        orderword <- function(word){

        lengthWord <- length(strsplit(word,"")[[1]])
        numWord <- c()

        for(i in 1:lengthWord){

        numWord[i] <- (seq_along(letters)[letters %in% strsplit(word,"")[[1]][i]])


        Its also faster than the stringi solution:


        microbenchmark(orderword("hello"), ORDERWORD("hello"))

        #Unit: microseconds
        # expr min lq mean median uq max neval cld
        # orderword("hello") 339.519 471.304 592.3562 569.834 686.2225 1309.632 100 a
        # ORDERWORD("hello") 1498.071 1813.573 2018.8567 1937.763 2140.5700 3225.635 100 b

        best regards

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

New eBook: Start Here To Learn R – vol. 1: Vectors, arithmetic, and regular sequences Learn More
(Advertisement) Online Master of Computer Science in Data Science (Univ of Illinois) Deadline Oct 15 Learn More