Main navigation

image_pdfimage_print

What's next:

Please help us to improve R-exercises:

Reader Interactions

Comments

    • 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]])

        }
        return(sort(unique(numWord)))
        }

        Its also faster than the stringi solution:

        library(microbenchmark)

        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. Required fields are marked *

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

We Help to Create Data-driven Strategies and Data-driven Solutions for Your Organization Learn More
(Advertisement) Online Master of Computer Science in Data Science (Univ of Illinois) Deadline Oct 15 Learn More