У меня есть фрейм данных с некоторыми измененными данными, но даты по столбцам / по ширине. Вот глава:
structure(list(Medium = c("(none)", "(not set)", "20190723-Sales-Tax-notification",
"20190729-Notification", "20190820_All_Others_Europe_Deprecation",
"20190820_PBX_Accounts_co-branded_Deprecation"), `01-Jan` = c(7443,
26, 3, 1, 1, 2), `02-Jan` = c(10283, 57, 6, 4, 3, 1), `03-Jan` = c(9753,
53, 15, 2, 1, 4), `04-Jan` = c(8129, 18, 7, 0, 4, 2), `05-Jan` = c(9209,
28, 5, 0, 2, 8), `06-Jan` = c(11617, 37, 21, 4, 3, 3), `07-Jan` = c(11768,
20, 8, 3, 0, 3), `08-Jan` = c(11267, 38, 12, 4, 0, 5), `09-Jan` = c(10790,
40, 10, 2, 2, 3), `10-Jan` = c(9733, 27, 5, 0, 0, 1), `11-Jan` = c(7372,
22, 8, 1, 5, 4), `12-Jan` = c(9119, 31, 4, 1, 2, 4), `13-Jan` = c(11642,
36, 12, 1, 4, 2), `14-Jan` = c(11226, 56, 8, 0, 4, 1), `15-Jan` = c(10841,
50, 5, 0, 6, 1), `16-Jan` = c(10471, 40, 9, 1, 2, 2), `17-Jan` = c(9774,
53, 9, 4, 0, 2), `18-Jan` = c(7655, 36, 9, 1, 3, 4), `19-Jan` = c(8341,
32, 10, 0, 3, 4), `20-Jan` = c(11191, 57, 10, 1, 2, 4), `21-Jan` = c(11284,
37, 13, 3, 0, 0), `22-Jan` = c(10810, 34, 16, 0, 3, 2), `23-Jan` = c(10162,
51, 10, 2, 1, 2), `24-Jan` = c(9570, 31, 0, 1, 0, 2), `25-Jan` = c(7409,
25, 1, 1, 0, 2), `26-Jan` = c(8286, 39, 1, 0, 2, 3), `27-Jan` = c(12750,
42, 0, 0, 1, 3), `28-Jan` = c(11308, 46, 1, 1, 3, 1), `29-Jan` = c(11189,
36, 2, 0, 1, 1), `30-Jan` = c(10472, 42, 0, 1, 1, 3), `31-Jan` = c(10107,
31, 0, 1, 0, 2), `01-Feb` = c(8392, 32, 0, 0, 4, 4), `02-Feb` = c(7940,
41, 0, 0, 2, 11), `03-Feb` = c(11766, 55, 0, 2, 4, 11), `04-Feb` = c(11601,
49, 0, 4, 3, 2), `05-Feb` = c(11212, 74, 0, 3, 2, 1), `06-Feb` = c(10868,
58, 0, 0, 1, 3), `07-Feb` = c(9602, 55, 1, 1, 0, 3), `08-Feb` = c(7685,
48, 0, 2, 0, 3), `09-Feb` = c(8842, 59, 0, 3, 3, 6), `10-Feb` = c(12087,
60, 1, 2, 3, 8), `11-Feb` = c(11484, 56, 3, 1, 6, 10), `12-Feb` = c(11050,
59, 0, 0, 3, 9), `13-Feb` = c(10905, 56, 1, 0, 2, 3), `14-Feb` = c(9245,
40, 0, 0, 2, 3), `15-Feb` = c(7446, 38, 1, 0, 0, 2), `16-Feb` = c(8348,
40, 3, 0, 4, 2), `17-Feb` = c(10961, 66, 0, 1, 2, 1), `18-Feb` = c(11349,
56, 2, 0, 2, 3), `19-Feb` = c(10829, 37, 0, 0, 0, 1), `20-Feb` = c(10611,
44, 0, 0, 0, 0), `21-Feb` = c(9372, 40, 0, 1, 0, 0), `22-Feb` = c(7597,
46, 0, 0, 0, 0), `23-Feb` = c(8514, 68, 0, 0, 0, 0), `24-Feb` = c(11553,
68, 0, 0, 0, 0), `25-Feb` = c(11309, 56, 0, 0, 0, 0), `26-Feb` = c(10958,
75, 0, 0, 0, 0), `27-Feb` = c(10703, 52, 0, 0, 0, 0), `28-Feb` = c(9544,
43, 0, 0, 0, 0), `29-Feb` = c(7723, 16, 2, 0, 0, 0), `01-Mar` = c(8985,
27, 0, 0, 0, 0), `02-Mar` = c(12130, 37, 0, 0, 0, 0), `03-Mar` = c(11235,
34, 1, 0, 0, 0), `04-Mar` = c(10930, 15, 0, 0, 0, 0), `05-Mar` = c(10454,
17, 0, 0, 0, 0), `06-Mar` = c(9206, 13, 0, 0, 0, 0), `07-Mar` = c(7301,
16, 0, 0, 0, 0), `08-Mar` = c(7852, 28, 1, 1, 0, 0), `09-Mar` = c(11011,
29, 2, 1, 0, 0), `10-Mar` = c(11309, 9, 0, 0, 0, 0), `11-Mar` = c(10426,
13, 0, 1, 0, 0), `12-Mar` = c(9326, 28, 0, 0, 0, 0), `13-Mar` = c(8244,
18, 0, 0, 0, 1), `14-Mar` = c(6888, 10, 0, 0, 0, 0), `15-Mar` = c(7691,
12, 2, 0, 0, 0), `16-Mar` = c(9227, 15, 0, 0, 0, 0), `17-Mar` = c(9133,
15, 1, 0, 0, 0), `18-Mar` = c(8868, 18, 0, 0, 0, 0), `19-Mar` = c(8632,
14, 0, 1, 0, 0), `20-Mar` = c(7999, 16, 1, 0, 0, 0), `21-Mar` = c(6796,
8, 0, 0, 0, 1), `22-Mar` = c(6729, 8, 0, 0, 0, 0), `23-Mar` = c(8897,
10, 0, 0, 0, 0), `24-Mar` = c(8755, 13, 0, 0, 0, 0), `25-Mar` = c(8947,
5, 0, 0, 0, 0), `26-Mar` = c(8229, 8, 0, 0, 0, 0), `27-Mar` = c(7951,
12, 1, 0, 0, 0), `28-Mar` = c(6926, 10, 0, 0, 0, 0), `29-Mar` = c(7112,
5, 2, 0, 0, 0), `01-Apr` = c(8282, 8, 0, 0, 0, 0), `02-Apr` = c(8041,
16, 0, 0, 0, 0), `03-Apr` = c(7728, 9, 0, 0, 0, 0), `04-Apr` = c(6307,
7, 1, 0, 0, 0), `05-Apr` = c(6341, 7, 1, 0, 0, 0), `06-Apr` = c(8241,
7, 0, 0, 0, 0), `07-Apr` = c(7575, 11, 0, 0, 0, 0), `08-Apr` = c(7719,
3, 0, 0, 0, 0), `09-Apr` = c(7707, 4, 0, 0, 0, 0), `10-Apr` = c(7487,
0, 0, 0, 0, 0), `11-Apr` = c(6159, 3, 0, 0, 0, 0)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
Выглядит так:
# A tibble: 6 x 101
Medium `01-Jan` `02-Jan` `03-Jan` `04-Jan` `05-Jan` `06-Jan` `07-Jan` `08-Jan` `09-Jan` `10-Jan` `11-Jan`
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (none) 7443 10283 9753 8129 9209 11617 11768 11267 10790 9733 7372
2 (not … 26 57 53 18 28 37 20 38 40 27 22
3 20190… 3 6 15 7 5 21 8 12 10 5 8
4 20190… 1 4 2 0 0 4 3 4 2 0 1
5 20190… 1 3 1 4 2 3 0 0 2 0 5
6 20190… 2 1 4 2 8 3 3 5 3 1 4
Итак, для каждой даты и функции 'medium' есть значение session, Я хотел бы вставить столбец между средним и текущим 1 января, т.е. вставить новый второй столбец после среднего, который содержит общую сумму всех оставшихся числовых полей c в этой строке. Я посмотрел на rowSums, но не смог понять, как использовать его в этом контексте.
Как добавить новый столбец, содержащий общее количество сеансов для каждого носителя?