{"id":322466,"date":"2021-05-02T09:00:07","date_gmt":"2021-05-02T09:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=322466"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=322466","title":{"rendered":"R \u0432 \u0440\u0443\u043a\u0430\u0445 \u043c\u0430\u0440\u043a\u0435\u0442\u043e\u043b\u043e\u0433\u0430. \u0414\u0435\u043b\u0430\u0435\u043c \u043a\u043e\u0433\u043e\u0440\u0442\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%92%D0%B8%D0%BD%D1%82%D0%B0%D0%B6%D0%BD%D1%8B%D0%B9_%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7\" rel=\"nofollow noopener noreferrer\">\u043a\u043e\u0433\u043e\u0440\u0442\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437<\/a>. \u0415\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u0430, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0435\u0442, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0430\u044f \u0432 excel. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0441\u0430\u0439\u0442\u043e\u0432 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u043e\u0436\u0438\u0442\u0438\u044f. <\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438 \u0435\u0435 \u043d\u0430\u0434\u043e \u0440\u0435\u0448\u0438\u0442\u044c. \u0418\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043f\u0430\u043a\u0435\u0442\u044b \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043c\u0430\u0441\u0441\u0430. \u041d\u0438\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u043e\u0439 \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u0438 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f), \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u043f\u0430\u0440\u0443 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<p>  <\/p>\n<p>\u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/habrahabr.ru\/users\/i_shutov\/posts\/\" rel=\"nofollow noopener noreferrer\">\u0441\u0435\u0440\u0438\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439<\/a>.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"nemnogo-koda\">\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/h1>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u042b\u0445 \u0437\u043e\u043d\u0430\u0445, \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 15 \u043d\u0435\u0434\u0435\u043b\u044c set.seed(42)  events_dt &lt;- tibble(user_id = 1000:9000) %&gt;%   mutate(birthday = Sys.Date() + as.integer(rexp(n(), 1\/10))) %&gt;%   rowwise() %&gt;%   mutate(timestamp = list(as_datetime(birthday) + 24*60*60 * (      rexp(10^3, rate = 1\/runif(1, 2, 25))))) %&gt;%   ungroup() %&gt;%   unnest(timestamp) %&gt;%   # \u0440\u0435\u0436\u0435\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u0445\u0432\u043e\u0441\u0442\u044b \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0438 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c   filter(timestamp &gt;= quantile(timestamp, probs = 0.1),          timestamp &lt;= quantile(timestamp, probs = 0.95)) %&gt;%   mutate(date = as_date(timestamp)) %&gt;%   select(user_id, date) %&gt;%   setDT(key = c(&quot;user_id&quot;, &quot;date&quot;)) %&gt;%   # \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e \u0434\u0430\u0442\u0430\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u044f   unique()<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">ggplot(events_dt, aes(date)) +   geom_histogram()<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jj\/a3\/s2\/jja3s290are020cc_fajqqfufoi.png\"><\/p>\n<p>  <\/p>\n<h2 id=\"shag-1-formiruem-spravochnik-polzovateley\">\u0428\u0430\u0433 1. \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e &quot;\u0434\u0430\u0442\u0443 \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f&quot;, \u0442.\u0435. \u0434\u0430\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0438\u0441\u044c \u0441 \u043d\u0438\u043c. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f <code>data.table<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0439.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">users_dict &lt;- events_dt[, .(birthday = head(date, 1)), by = user_id] %&gt;%   # \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0434\u0430\u0442\u0443 \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u0434\u0435\u043b\u0438   .[, week_start := floor_date(.BY[[1]], unit = &quot;week&quot;), by = birthday] %&gt;%     # \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0434\u0430\u0442\u044b \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0432 \u043d\u043e\u043c\u0435\u0440\u0430 \u043a\u043e\u0433\u043e\u0440\u0442   .[, cohort := stri_c(         lubridate::isoyear(.BY[[1]]),          sprintf(&quot;%02d&quot;, lubridate::isoweek(.BY[[1]])),          sep = &quot;\/&quot;), by = week_start] # \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u0442, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 as_tibble(janitor::tabyl(users_dict, birthday))<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sr\/wu\/tw\/srwutw7nxkoqzoeonynccqrax2w.png\"><\/p>\n<p>  <\/p>\n<h2 id=\"shag-2-podgotovim-razmetku-v-terminah-kogortnogo-analiza\">\u0428\u0430\u0433 2. \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043a\u043e\u0433\u043e\u0440\u0442\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0432\u0441\u0435\u043c \u0437\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0433\u043e\u043d\u0438\u043c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u043a\u043e\u0433\u043e\u0440\u0442. \u0414\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0421\u0442\u0440\u043e\u0438\u043c \u043a\u043e\u0433\u043e\u0440\u0442\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 data.frame<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">cohort_dict &lt;- unique(users_dict[, .(cohort, week_start)])  cohort_tbl &lt;- users_dict[events_dt, on = &quot;user_id&quot;] %&gt;%   # \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442 \u0434\u0430\u0442\u044b \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043d\u0435\u0434\u0435\u043b\u044c   .[, rel_week := floor(as.numeric(difftime(date, birthday, units = &quot;week&quot;)))] %&gt;%   # \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e 10 \u043d\u0435\u0434\u0435\u043b\u044c   .[rel_week &lt;= 9] %&gt;%   # \u0440\u0435\u0434\u0443\u0446\u0438\u0440\u0443\u0435\u043c \u0434\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439   unique(by = c(&quot;user_id&quot;, &quot;cohort&quot;, &quot;rel_week&quot;)) %&gt;%   # \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043a\u043e\u0433\u043e\u0440\u0442 \u0438 \u043d\u0435\u0434\u0435\u043b\u044c   .[, .N, by = .(cohort, rel_week)] %&gt;%   .[, rate := N\/max(N), by = cohort]<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"shag-3-vizualiziruem\">\u0428\u0430\u0433 3. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c<\/h2>\n<p>  <\/p>\n<h3 id=\"variant-1-ggplot\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1. <code>ggplot<\/code><\/h3>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f  ggplot<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0432\u0430\u0440\u0438\u0430\u043d\u0442 ggplot data_tbl &lt;- cohort_tbl %&gt;%   # \u0432\u0435\u0440\u043d\u0435\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043a\u043e\u0433\u043e\u0440\u0442 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438   left_join(cohort_dict)  data_tbl %&gt;%   mutate(cohort_group = forcats::fct_reorder(cohort, week_start, .desc = TRUE)) %&gt;%   ggplot(mapping = aes(x = rel_week, y = cohort_group, fill = rate)) +   geom_tile()  +   geom_text(aes(label = N), colour = &quot;darkgray&quot;) +   labs(x = &quot;\u041d\u0435\u0434\u0435\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0433\u043e\u0440\u0442\u044b&quot;,        y = &quot;\u041d\u0435\u0434\u0435\u043b\u044f \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u043e\u0440\u0442\u044b&quot;,        fill = &quot;\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\\n\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439&quot;,        title = &quot;graph_title&quot;) +   scale_fill_viridis_c(option = &quot;inferno&quot;) +   scale_x_continuous(breaks = scales::breaks_width(1)) +   theme_minimal() +   theme(panel.grid = element_blank())<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sz\/o9\/e-\/szo9e-alb3ojekebezsmfc1zflm.png\"><\/p>\n<p>  <\/p>\n<h3 id=\"variant-2-gt\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2. <code>gt<\/code><\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043a\u043e\u0433\u043e\u0440\u0442\u0443 \u0438 \u043e\u043d\u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f gt<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443-\u043f\u043e\u0434\u043b\u043e\u0436\u043a\u0443 data_tbl &lt;- cohort_tbl %&gt;%   pivot_longer(cols = c(N, rate)) %&gt;%   pivot_wider(names_from = rel_week, values_from = value) %&gt;%   # \u0432\u0435\u0440\u043d\u0435\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043a\u043e\u0433\u043e\u0440\u0442 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438   left_join(cohort_dict) %&gt;%   arrange(week_start, desc(name))  odd_rows &lt;- seq(1, to = nrow(data_tbl), by = 2) even_rows &lt;- seq(2, to = nrow(data_tbl), by = 2)  tab &lt;- data_tbl %&gt;%   mutate(cohort = if_else(rep(c(TRUE, FALSE), length.out = nrow(.)),                            cohort, &quot;&quot;)) %&gt;%   select(-name, -week_start) %&gt;%   gt(rowname_col = &quot;cohort&quot;) %&gt;%   fmt_percent(columns = matches(&quot;[0-9]+&quot;),                rows = odd_rows,                decimals = 0, pattern = &quot;&lt;big&gt;{x}&lt;\/big&gt;&quot;) %&gt;%   fmt_missing(columns = everything(),                missing_text = &quot;---&quot;) %&gt;%   tab_stubhead(label = &quot;\u041d\u0435\u0434\u0435\u043b\u044f \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u043e\u0440\u0442\u044b&quot;) %&gt;%   tab_spanner(label = &quot;\u041d\u0435\u0434\u0435\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0433\u043e\u0440\u0442\u044b&quot;,               columns = everything()) %&gt;%   tab_header(title = &quot;\u0420\u0430\u0437\u0432\u0435\u0440\u0442\u043a\u0430&quot;) %&gt;%   data_color(columns = everything(),              colors = scales::col_numeric(palette = &quot;inferno&quot;,                                           domain = c(0, 1),                                            alpha = 0.6,                                           na.color = &quot;lightgray&quot;)) %&gt;%   tab_options(     table.font.size = &quot;smaller&quot;,     data_row.padding = px(1),     table.width = pct(75)   ) %&gt;%   tab_style(     style = list(       cell_fill(color = &quot;white&quot;),       cell_text(style = &quot;italic&quot;),       cell_borders(sides = &quot;bottom&quot;)     ),     locations = cells_body(       columns = everything(),       rows = even_rows)   ) %&gt;%   tab_style(     style = list(       cell_borders(sides = &quot;top&quot;)     ),     locations = cells_body(       columns = everything(),       rows = odd_rows)   )  tab<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jb\/70\/a7\/jb70a735lrl-iodtqzeawmegbmo.png\"><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u0440\u043a\u0430\u0441 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d, \u043f\u0440\u043e\u0447\u0435\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u0441\u0435\u0431\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u2014 <a href=\"https:\/\/habr.com\/ru\/post\/555126\/\">\u00abR \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c. \u0427\u0442\u043e \u0437\u0430 \u043a\u0443\u043b\u0438\u0441\u0430\u043c\u0438?\u00bb<\/a>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/555476\/\"> https:\/\/habr.com\/ru\/post\/555476\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%92%D0%B8%D0%BD%D1%82%D0%B0%D0%B6%D0%BD%D1%8B%D0%B9_%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7\" rel=\"nofollow noopener noreferrer\">\u043a\u043e\u0433\u043e\u0440\u0442\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437<\/a>. \u0415\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u0430, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0435\u0442, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u0430\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u0430\u044f \u0432 excel. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0441\u0430\u0439\u0442\u043e\u0432 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u043e\u0436\u0438\u0442\u0438\u044f. <\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438 \u0435\u0435 \u043d\u0430\u0434\u043e \u0440\u0435\u0448\u0438\u0442\u044c. \u0418\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043f\u0430\u043a\u0435\u0442\u044b \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043c\u0430\u0441\u0441\u0430. \u041d\u0438\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u0431\u0435\u0437 \u043e\u0441\u043e\u0431\u043e\u0439 \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u0438 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f), \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 \u043f\u0430\u0440\u0443 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<p>  <\/p>\n<p>\u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/habrahabr.ru\/users\/i_shutov\/posts\/\" rel=\"nofollow noopener noreferrer\">\u0441\u0435\u0440\u0438\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439<\/a>.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-322466","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322466"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322466\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}