0

I have a table that lists participants, the app they were using on their phones, and the duration of each session. It looks like this:

  panelist_id                        app_name duration
1       550302                        Messages  10 secs
3       550302                          Google   2 secs
5       550302 com.google.android.partnersetup  20 secs
7       550302                          Google   8 secs
9       550302                          Google  30 secs
11      550302                          Dialer   8 secs

I want to tabulate the above to inspect total time spent on an app by participant. So hopefully it should like this:

                 55302 550303 55304                        
1       Messages  1040  1000   458                    
3       Google    900   580    345                    
5       Dialer    800   150    340
7       Facebook  513   1549   418                   

The number of apps is more than 5000 and there are 100 users so manually inserting the column and row names is not an option.

I have tried achieving this by building a frequency table but it didn't get me very far.

This is my first time posting a question so apologies for any mistakes and thanks in advance!

Aris
  • 1
  • 2
  • The other question you suggest is very similar indeed but does not provide any info on how to sort by two different variables. Using the same code I get an issue of "arguments must have same length". – Aris Jul 14 '16 at 13:53

1 Answers1

0

Using dplyr you could write something like this:

library(dplyr)
data %>% group_by(app_name, panelist_id) %>% summarize(total_duration = sum(duration))
dratewka
  • 2,104
  • 14
  • 15
  • Thanks! What I get back looks like this: app_name panelist_id total_duration 1 #SquareDroid \\u2014 Full Size Photo 598136 18 secs 2 µTorrent® - Torrent Downloader 590543 1372 secs In the current form however I get duplicate entries of both apps and panelists making it hard to analyse afterwards. Hopefully I could extract it into a csv afterwards to analyse. – Aris Jul 14 '16 at 13:29