Open EmilHvitfeldt opened 1 year ago
library(friends)
friends
dict <- c(a = 1, b = 3, c = 3, d = 2, e = 1, f = 4, g = 2, h = 4, i = 1,
k = 5, k = 8, l = 1, m = 3, n = 1, o = 1, p = 3, q = 10, r = 1,
s = 1, t = 1, u = 1, v = 4, w = 4, x = 8, y = 4, z = 10)
scabble <- function(x) {
tiles <- stringr::str_split(tolower(x), "")
purrr::map_dbl(tiles, ~ sum(dict[.x], na.rm = TRUE))
}
library(tidyverse)
top_friends <- friends |>
count(speaker, sort = TRUE) |>
slice_head(n = 6)
friends |>
inner_join(top_friends, by = "speaker") |>
mutate(text_scrabble = scabble(text)) |>
mutate(text_length = str_length(str_remove_all(text, "[^A-z]"))) |>
mutate(text_spc = text_scrabble / text_length) |>
mutate(row_number = row_number()) |>
drop_na() |>
group_by(speaker, season, episode) |>
summarise(mean_spc = mean(text_spc), .groups = "drop") |>
group_by(speaker) |>
mutate(episode_real = row_number()) |>
ungroup() |>
ggplot(aes(episode_real, mean_spc, color = speaker)) +
geom_point() +
geom_smooth()
Turns characters into their scrabble scores