Für Vorlesungen, bitte die Webseite verwenden. https://flavigny.de/lecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0KB

  1. # Josua Kugler, Christian Merten
  2. library(tidyverse)
  3. `%o%` <- function(f, g) function(...) f(g(...))
  4. # ich bin mal so dreist und lese das gesamte file direkt ein
  5. # wenn hier unbedingt read_lines verwendet werden soll, dann füge
  6. # man eben zuerst mit paste alle zeilen wieder zusammen
  7. lines <- read_file("books.txt")
  8. sort_char <- function(s) paste(sort(unlist(str_split(s, ""))), sep="", collapse="")
  9. cleared <- str_match_all(str_to_upper(str_replace_all(lines,
  10. pattern="\\(.*?\\)|[^a-zA-Z0-9]",
  11. replacement="")),
  12. "([A-Z]+)([0-9]+)")[[1]]
  13. unsorted_data <- tibble(category = sapply(cleared[,2], sort_char),
  14. count = as.integer(cleared[,3]))
  15. data <- unsorted_data[order(unsorted_data[,1]),]
  16. books_of_category <- function(data, cat_let) {
  17. apply(data[str_detect(data$category, cat_let), ], 1,
  18. function(x) str_glue("We have {x[2]} books of category {x[1]}"))
  19. }