如何计算每个客户每月的电子邮件选择数



在我的硕士论文中,我试图总结客户在一段时间内(每月)所有可能的新闻通讯的选择总数。我做不到。

Dput() data to replication the set:

structure(list(GroupID = c(404712L, 404722L, 404722L, 404722L, 
404722L, 404731L, 404731L, 404731L, 404731L, 404776L, 404776L, 
404776L, 404776L, 404845L, 404845L), MailingListName = c("Ticketing", 
"Merchandise", "Nieuwsbrief", "Partners", "Ticketing", "Merchandise", 
"Nieuwsbrief", "Partners", "Ticketing", "Merchandise", "Nieuwsbrief", 
"Partners", "Ticketing", "Merchandise", "Nieuwsbrief"), OptIn = c("1", 
"0", "0", "0", "0", "1", "1", "0", "1", "1", "1", "0", "1", "1", 
"1"), modifieddate = structure(c(17454, 17957, 17957, 17957, 
17957, 17455, 17455, 17455, 17455, 17901, 17901, 17901, 17901, 
18665, 18665), class = "Date"), modifieddate_Yr_Month = c("2017-10", 
"2019-03", "2019-03", "2019-03", "2019-03", "2017-10", "2017-10", 
"2017-10", "2017-10", "2019-01", "2019-01", "2019-01", "2019-01", 
"2021-02", "2021-02")), row.names = c(NA, -15L), class = c("data.table", 
"data.frame"))

I trieddplyr:

library(dplyr)
dfnewsletters_total <- dfnewsletters %>%
group_by(OptIn, GroupID, modifieddate_Yr_Month) %>%
mutate(OptIn_Total = n()) %>%
arrange(desc(OptIn_Total))

没有任何好的结果。

有人知道如何解决这个问题吗?

Nieuwsbrief = Newsletter?

library(dplyr)
dfnewsletters %>%
filter(MailingListName == "Nieuwsbrief") %>% 
group_by(GroupID, modifieddate_Yr_Month) %>%
summarise(OptIn_Total = sum(as.numeric(OptIn))) %>% 
arrange(desc(OptIn_Total))

输出:

GroupID modifieddate_Yr_Month OptIn_Total
<int> <chr>                       <dbl>
1  404731 2017-10                         1
2  404776 2019-01                         1
3  404845 2021-02                         1
4  404722 2019-03                         0

最新更新