I have a Dataset, I want to calculate average of KPI, CPM and CPC column and count times column in each score group(1-10).
How to create a new table according results?>
assuming your data is in a data.frame called df, do you just want this?
library(data.table)
setDT(df)[ ,.(lapply(.SD, mean), .N), by = score, .SDcols = c("KPI", "CPM", "CPC")]
or do you want this?
library(dplyr)
group_by(df, score) %>%
summarise(Mean_KPI = mean(KPI),
Mean_CPC = mean(CPC),
Mean_CPM = mean(CPM),
Sum_times = sum(times))