1

I have a df with sessions of clients with for every session the duration. I want to have a new df where I have per client the avergage session duration. The sessionid's and client id's are rendom generated numbers in my data, but I simplified it here to be more clear.

My data looks like:

Sessionid    Clientid    Session_duration
    1           1               40
    2           1               10
    3           1               100
    4           2               32
    5           2               12 
    6           3               3

I want to have output like:

Clientid    avg_session_duration
   1                 50
   2                 22
   3                 3

I tried this the following code, but then I get only the average of the whole column.

mydata %>% 
  group_by(Clientid) %>% 
  summarise(avg_session = mean(Session_duration, na.rm = T))

EDIT: the problem was what Henrik highlighted. After detaching the plyer and dyplr packages and loading the dplyr again it worked.

Joost
  • 101
  • 5

0 Answers0