Summarise values in columns

Hello, colleagues

My script

googleads_report %>%
mutate(sourceMedium = "google / cpc") %>%
dplyr::select(date, sourceMedium, campaign_name, impressions, clicks, cost, device) %>%
dplyr::rename(campaign = campaign_name),

yadir_report %>%
mutate(sourceMedium = "yandex / cpc") %>%
dplyr::select(Date, sourceMedium, CampaignName, Impressions, Clicks, Cost, Device) %>%
dplyr::rename(date = Date, campaign = CampaignName, impressions = Impressions,clicks = Clicks, cost = Cost, device = Device)
) %>%
mutate(device = case_when(
grepl("DESKTOP", device, = T) ~ "desktop",
grepl(".(Mobile|TABLET|CONNECTED_TV).", device, = T) ~ "mobile",
TRUE ~ "others")) %>%
group_by(date, sourceMedium, campaign, impressions, clicks, cost, device) %>%
summarise(cost = sum(cost)) %>%

I can't summarise values in columns "impressions", "clicks", "cost" by column "device" after i renamed
".(Mobile|TABLET|CONNECTED_TV). to "mobile".

On the screen we can see that each campaign contains two devices "mobile" and they don`t summarise.

Hi, can you provide a reproducible example? It will make it easier for others to help you.

@williaml Hi,

I solved the problem. Function "group_by" doesn`t group numeric columns like clicks, cost, etc.

group_by(date, sourceMedium, campaign, device) %>%
summarise(impressions = sum(impressions), clicks = sum(clicks), cost = sum(cost))

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.