I had hoped to use ddply's mode function to find the most common string for a certain user by time period.
This relates significantly to this question and this question.
Using a data set similar to this:
Data <- data.frame(
groupname = as.factor(sample(c("red", "green", "blue"), 100, replace = TRUE)),
timeblock = sample(1:10, 100, replace = TRUE),
someuser = sample(c("bob", "sally", "sue"), 100, replace = TRUE))
I'd tried:
groupnameagg<- ddply(Data, .(timeblock, groupname, someuser), summarise, groupmode = mode(groupname))
But that's not doing what I had expected. It returns:
> head(groupnameagg$groupname)
[1] "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
- How can I find the most commonly occurring groupname by user by timeblock? With a result similar to:
timeblock username mostcommongroupforuser
1 bob red
1 sally red
1 sue green
2 bob green
2 sally blue
2 sue red
- If groupname is organized by levels, how might I get the highest level present in each timeblock?