I'm having a dataframe with both numerical and categorical variables.
The data frame has 2 keys where I need group by. When the rows are grouped by keys so & li, then categorical variables need to be selected based on mode & numerical by average.
   SO      LI        A         B
1 2000     20        P          22
2 2000     20        P          40
3 1000     10        Q          80
The output needs to be,
   SO      LI        A         B
1 2000     20        P          31
2 1000     10        Q          80
I used the following code so far.
library(plyr)
groupColumns = c("so","li")
dataColumns = c(colnames(numericalColumns(Planning_DF)))
res = ddply(Planning_DF, groupColumns, function(x) colMeans(x[dataColumns]))
head(res)
so the numerical column grouping & average happening. How to get the categorical variables Mode to this?
 
    