Home > Mobile >  R, How to keep rows after, and/or between values split by group?
R, How to keep rows after, and/or between values split by group?

Time:10-07

Sorry my dput function was giving a nonsense output for some reason. I have a df with User IDs and events. I am trying to build a path for each user ID starting from the Event $identify. How do I only keep the first 5 rows after the $identify for each ID? The output should have each ID plus the next 5 events. The dataframe is already sorted by userID and Date so no need to do that just maintain the order.

Sample output

ID datetime Event
ID1232 9:00AM $identify
ID1232 9:01AM Dropdown Menu

Repeated for each ID

testset <- wrapr::build_frame(
   "user_id"                               , "datetime"        , "event"                                   |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Dropdown Menu - Open"                    |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Dropdown Menu - Settings"                |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Dropdown Menu - View Profile"            |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Profile - Edit"                          |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Profile - Close"                         |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Dropdown Menu - Directory"               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:10 AM", "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:11 AM", "Directory - Close"                       |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:12 AM", "2D - Directory Icon"                     |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:12 AM", "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:13 AM", "Directory - Close"                       |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:13 AM", "Dropdown Menu - Open"                    |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:13 AM", "Dropdown Menu - Settings"                |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:13 AM", "Dropdown Menu - View Profile"            |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:13 AM", "Profile - Edit"                          |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:14 AM", "Profile' - Save"                         |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:14 AM", "Dropdown Menu - Help"                    |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:14 AM", "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:14 AM", "Help - Close"                            |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 10:27 AM", "Chat - Search User"                      |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 11:47 AM", "Dropdown Menu - Open"                    |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 11:55 AM", "Dropdown Menu - Agenda"                  |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 11:55 AM", "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:43 AM" , "$identify"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:43 AM" , "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:43 AM" , "Onboarding - Next"                       |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:44 AM" , "Dimension Choice - Choice Made"          |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:44 AM" , "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:46 AM" , "Dimension Choice - Choice Made"          |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:46 AM" , "Dropdown Menu - Open"                    |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:46 AM" , "Dropdown Menu - Settings"                |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:46 AM" , "Dropdown Menu - Sound Off"               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:47 AM" , "Chat - Search User"                      |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:47 AM" , "Chat - Invite a Person to Groupchat"     |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:47 AM" , "Chat - Enter Message"                    |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:50 AM" , "Page View"                               |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:50 AM" , "Dimension Choice - Choice Made"          |
     "0106d45f-deda-4205-894a-006c8afa5abc", "9/21/21 9:50 AM" , "Chat - Join a Videochat"                 |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:32 PM" , "$identify"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:32 PM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:32 PM" , "Onboarding - Next"                       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:32 PM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:32 PM" , "2D - Agenda Icon"                        |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:32 PM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:36 PM" , "Agenda - Close"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:36 PM" , "2D - Directory Icon"                     |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:36 PM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:36 PM" , "Profile - View"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:37 PM" , "Profile - Close"                         |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:37 PM" , "Directory - Next page participant"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:37 PM" , "Directory - Filter"                      |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/21/21 8:38 PM" , "Directory - Close"                       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:00 AM", "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:00 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:01 AM", "Personal Agenda - Join The Session"      |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:01 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:01 AM", "Presentation - Open Modal"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:01 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:02 AM", "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:27 AM", "Presentation - Close Modal"              |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:27 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:27 AM", "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:27 AM", "Dropdown Menu - My Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:27 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:30 AM", "Presentation - Open Modal"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:30 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:30 AM", "Personal Agenda - Join The Session"      |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:30 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:31 AM", "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Presentation - Close Modal"              |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Dropdown Menu - My Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Personal Agenda - Remove from my Agenda" |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 10:58 AM", "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Dropdown Menu - My Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Dropdown Menu - Agenda"                  |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Agenda - Past Presentations"             |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 2:30 PM" , "Agenda - Close"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 7:48 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:00 AM" , "Login - Login Button"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:00 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:01 AM" , "2D - Agenda Icon"                        |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:01 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:39 AM" , "Agenda - Close"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:39 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:39 AM" , "2D - Agenda Icon"                        |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:49 AM" , "Presentation - Open Modal"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:49 AM" , "Agenda - Join the Session"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:49 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:49 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:50 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:50 AM" , "Presentation - Close Modal"              |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "2D - Agenda Icon"                        |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Agenda - Join the Session"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Presentation - Open Modal"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:51 AM" , "Presentation - Close Modal"              |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "$identify"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "3D - Agenda Icon"                        |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "Agenda - Join the Session"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "Presentation - Open Modal"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:52 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:53 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:56 AM" , "Presentation - Close Modal"              |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:56 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:56 AM" , "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:57 AM" , "Dropdown Menu - My Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:57 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:57 AM" , "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:57 AM" , "Dropdown Menu - Agenda"                  |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:57 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:57 AM" , "Agenda - Add to my Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Agenda - Close"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Dropdown Menu - My Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Dropdown Menu - Open"                    |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Dropdown Menu - Agenda"                  |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Agenda - Add to my Agenda"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Agenda - Close"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Rooms Nav - Open"                        |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "3D - Join a Session Icon"                |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Presentation - Open Modal"               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:58 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 8:59 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:00 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:00 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:02 AM" , "Personal Agenda - Join The Session"      |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:02 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:02 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:11 AM" , "Profile - View"                          |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:12 AM" , "Profile - Close"                         |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:12 AM" , "Presentation - Watch Presentation"       |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:16 AM" , "Page View"                               |
     "01370990-cc35-4be4-8927-39e83b7f1e76", "9/22/21 9:16 AM" , "Presentation - Close Modal"              )

How would I alter the code below to start with

test2<-testset%>%
  arrange(user_id, datetime)%>%
  group_by(user_id)%>%
  mutate(group = cumsum(event == "Welcome - Confirm Emails")) %>%
  group_by(user_id, group) %>%
  filter(event[1] == "Welcome - Confirm Emails") %>%
  summarise(touches = paste(event, collapse = "_"),
            first_touch = min(datetime))%>%
  slice(1:(which(event == "$identify")))%>%
  ungroup()

this did not work. After running the code with the initial answer I realize I need to have identify as the last event, when followed by "Welcome - Confirm Emails"

CodePudding user response:

This is a straight-forward grouping operation, but there's a twist: at least one user_id has multiple $identify lines, in which case you need to check for both.

base R

testset$group <- ave(testset$event, testset$user_id,
                     FUN = function(z) cumsum(z == "$identify"))
keep <- ave(testset$event, testset[,c("user_id", "group")],
            FUN = function(z) {
              if (length(z) && z[1] == "$identify") (seq_along(z) <= 5) else FALSE
            }) == "TRUE"
testset[keep,]
#                                  user_id        datetime                          event group
# 25  0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 9:43 AM                      $identify     1
# 26  0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 9:43 AM                      Page View     1
# 27  0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 9:43 AM              Onboarding - Next     1
# 28  0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 9:44 AM Dimension Choice - Choice Made     1
# 29  0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 9:44 AM                      Page View     1
# 40  01370990-cc35-4be4-8927-39e83b7f1e76 9/21/21 8:32 PM                      $identify     1
# 41  01370990-cc35-4be4-8927-39e83b7f1e76 9/21/21 8:32 PM                      Page View     1
# 42  01370990-cc35-4be4-8927-39e83b7f1e76 9/21/21 8:32 PM              Onboarding - Next     1
# 43  01370990-cc35-4be4-8927-39e83b7f1e76 9/21/21 8:32 PM                      Page View     1
# 44  01370990-cc35-4be4-8927-39e83b7f1e76 9/21/21 8:32 PM               2D - Agenda Icon     1
# 108 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:52 AM                      $identify     2
# 109 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:52 AM                      Page View     2
# 110 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:52 AM               3D - Agenda Icon     2
# 111 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:52 AM                      Page View     2
# 112 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:52 AM      Agenda - Join the Session     2

dplyr

Similar to the other answer, handling multiple instances of $identify differently.

library(dplyr)
testset %>%
  group_by(user_id) %>%
  mutate(group = cumsum(event == "$identify")) %>%
  group_by(user_id, group) %>%
  filter(event[1] == "$identify" & row_number() <= 5) %>%
  ungroup()

data.table

library(data.table)
testsetDT <- as.data.table(testset)
testsetDT[, group := cumsum(event == "$identify"), by = user_id
          ][, .SD[event[1] == "$identify" & seq_len(.N) <= 5,], by = .(user_id, group)
            ]

For your second need (return rows between two events), it's difficult to test fully given that your data does not include "Welcome...", but I'll use "Page View" instead:

testset %>%
  group_by(user_id) %>%
  mutate(group = cumsum(event == "Page View")) %>%
  group_by(user_id, group) %>%
  filter(event[1] == "Page View" &
           "$identify" %in% event &
           (event == "$identify" | !cumany(event == "$identify"))) %>%
  ungroup()
# # A tibble: 5 x 4
#   user_id                              datetime         event                      group
#   <chr>                                <chr>            <chr>                      <int>
# 1 0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 11:55 AM Page View                      5
# 2 0106d45f-deda-4205-894a-006c8afa5abc 9/21/21 9:43 AM  $identify                      5
# 3 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:51 AM  Page View                     25
# 4 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:51 AM  Presentation - Close Modal    25
# 5 01370990-cc35-4be4-8927-39e83b7f1e76 9/22/21 8:52 AM  $identify                     25

Similar mechanisms can be used for base R and data.table solutions if required.


Data

testset <- structure(list(user_id = c("0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "0106d45f-deda-4205-894a-006c8afa5abc", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76", "01370990-cc35-4be4-8927-39e83b7f1e76"), datetime = c("9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:10 AM", "9/21/21 10:11 AM", "9/21/21 10:12 AM", "9/21/21 10:12 AM", "9/21/21 10:13 AM", "9/21/21 10:13 AM", "9/21/21 10:13 AM", "9/21/21 10:13 AM", "9/21/21 10:13 AM", "9/21/21 10:14 AM", "9/21/21 10:14 AM", "9/21/21 10:14 AM", "9/21/21 10:14 AM", "9/21/21 10:27 AM", "9/21/21 11:47 AM", "9/21/21 11:55 AM", "9/21/21 11:55 AM", "9/21/21 9:43 AM", "9/21/21 9:43 AM", "9/21/21 9:43 AM", "9/21/21 9:44 AM", "9/21/21 9:44 AM", "9/21/21 9:46 AM", "9/21/21 9:46 AM", "9/21/21 9:46 AM", "9/21/21 9:46 AM", "9/21/21 9:47 AM", "9/21/21 9:47 AM", "9/21/21 9:47 AM", "9/21/21 9:50 AM", "9/21/21 9:50 AM", "9/21/21 9:50 AM", "9/21/21 8:32 PM", "9/21/21 8:32 PM", "9/21/21 8:32 PM", "9/21/21 8:32 PM", "9/21/21 8:32 PM", "9/21/21 8:32 PM", "9/21/21 8:36 PM", "9/21/21 8:36 PM", "9/21/21 8:36 PM", "9/21/21 8:36 PM", "9/21/21 8:37 PM", "9/21/21 8:37 PM", "9/21/21 8:37 PM", "9/21/21 8:38 PM", "9/22/21 10:00 AM", "9/22/21 10:00 AM", "9/22/21 10:01 AM", "9/22/21 10:01 AM", "9/22/21 10:01 AM", "9/22/21 10:01 AM", "9/22/21 10:02 AM", "9/22/21 10:27 AM", "9/22/21 10:27 AM", "9/22/21 10:27 AM", "9/22/21 10:27 AM", "9/22/21 10:27 AM", "9/22/21 10:30 AM", "9/22/21 10:30 AM", "9/22/21 10:30 AM", "9/22/21 10:30 AM", "9/22/21 10:31 AM", "9/22/21 10:58 AM", "9/22/21 10:58 AM", "9/22/21 10:58 AM", "9/22/21 10:58 AM", "9/22/21 10:58 AM", "9/22/21 10:58 AM", "9/22/21 10:58 AM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 2:30 PM", "9/22/21 7:48 AM", "9/22/21 8:00 AM", "9/22/21 8:00 AM", "9/22/21 8:01 AM", "9/22/21 8:01 AM", "9/22/21 8:39 AM", "9/22/21 8:39 AM", "9/22/21 8:39 AM", "9/22/21 8:49 AM", "9/22/21 8:49 AM", "9/22/21 8:49 AM", "9/22/21 8:49 AM", "9/22/21 8:50 AM", "9/22/21 8:50 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:51 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:52 AM", "9/22/21 8:53 AM", "9/22/21 8:56 AM", "9/22/21 8:56 AM", "9/22/21 8:56 AM", "9/22/21 8:57 AM", "9/22/21 8:57 AM", "9/22/21 8:57 AM", "9/22/21 8:57 AM", "9/22/21 8:57 AM", "9/22/21 8:57 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:58 AM", "9/22/21 8:59 AM", "9/22/21 9:00 AM", "9/22/21 9:00 AM", "9/22/21 9:02 AM", "9/22/21 9:02 AM", "9/22/21 9:02 AM", "9/22/21 9:11 AM", "9/22/21 9:12 AM", "9/22/21 9:12 AM", "9/22/21 9:16 AM", "9/22/21 9:16 AM"), event = c("Page View", "Dropdown Menu - Open", "Dropdown Menu - Settings", "Dropdown Menu - View Profile", "Profile - Edit", "Profile - Close", "Dropdown Menu - Directory", "Page View", "Directory - Close", "2D - Directory Icon", "Page View", "Directory - Close", "Dropdown Menu - Open", "Dropdown Menu - Settings", "Dropdown Menu - View Profile", "Profile - Edit", "Profile' - Save", "Dropdown Menu - Help", "Page View", "Help - Close", "Chat - Search User", "Dropdown Menu - Open", "Dropdown Menu - Agenda", "Page View", "$identify", "Page View", "Onboarding - Next", "Dimension Choice - Choice Made", "Page View", "Dimension Choice - Choice Made", "Dropdown Menu - Open", "Dropdown Menu - Settings", "Dropdown Menu - Sound Off", "Chat - Search User", "Chat - Invite a Person to Groupchat", "Chat - Enter Message", "Page View", "Dimension Choice - Choice Made", "Chat - Join a Videochat", "$identify", "Page View", "Onboarding - Next", "Page View", "2D - Agenda Icon", "Page View", "Agenda - Close", "2D - Directory Icon", "Page View", "Profile - View", "Profile - Close", "Directory - Next page participant", "Directory - Filter", "Directory - Close", "Presentation - Watch Presentation", "Page View", "Personal Agenda - Join The Session", "Page View", "Presentation - Open Modal", "Page View", "Presentation - Watch Presentation", "Presentation - Close Modal", "Page View", "Dropdown Menu - Open", "Dropdown Menu - My Agenda", "Page View", "Presentation - Open Modal", "Page View", "Personal Agenda - Join The Session", "Page View", "Presentation - Watch Presentation", "Presentation - Close Modal", "Page View", "Dropdown Menu - Open", "Dropdown Menu - My Agenda", "Page View", "Personal Agenda - Remove from my Agenda", "Page View", "Dropdown Menu - Open", "Dropdown Menu - My Agenda", "Page View", "Dropdown Menu - Open", "Dropdown Menu - Agenda", "Page View", "Agenda - Past Presentations", "Agenda - Close", "Page View", "Login - Login Button", "Page View", "2D - Agenda Icon", "Page View", "Agenda - Close", "Page View", "2D - Agenda Icon", "Presentation - Open Modal", "Agenda - Join the Session", "Page View", "Presentation - Watch Presentation", "Page View", "Presentation - Close Modal", "2D - Agenda Icon", "Page View", "Agenda - Join the Session", "Presentation - Open Modal", "Page View", "Presentation - Watch Presentation", "Page View", "Presentation - Close Modal", "$identify", "Page View", "3D - Agenda Icon", "Page View", "Agenda - Join the Session", "Page View", "Presentation - Open Modal", "Page View", "Presentation - Watch Presentation", "Presentation - Close Modal", "Page View", "Dropdown Menu - Open", "Dropdown Menu - My Agenda", "Page View", "Dropdown Menu - Open", "Dropdown Menu - Agenda", "Page View", "Agenda - Add to my Agenda", "Agenda - Close", "Dropdown Menu - Open", "Page View", "Dropdown Menu - My Agenda", "Page View", "Dropdown Menu - Open", "Dropdown Menu - Agenda", "Page View", "Agenda - Add to my Agenda", "Agenda - Close", "Rooms Nav - Open", "3D - Join a Session Icon", "Presentation - Open Modal", "Page View", "Presentation - Watch Presentation", "Page View", "Presentation - Watch Presentation", "Personal Agenda - Join The Session", "Page View", "Presentation - Watch Presentation", "Profile - View", "Profile - Close", "Presentation - Watch Presentation", "Page View", "Presentation - Close Modal")), row.names = c(NA, -150L), class = "data.frame")
  •  Tags:  
  • r
  • Related