Calculate average number of page visited before Signup

Viewed 32

I have a dataset that has three columns:

VisitorID - Id of visitor Page path - Pages that visitor visited Time - time when that page is visted

I am interested in answering the question: How many pages on average visitor visited before coming to the /signup page.

Sample table

So in this sample table, we know that visitor 265256310 visited 4 pages before coming to a /signup page. The second visitor also visited 4 pages before coming to a /signup page, so on average, we know that users needed 4 pages to get to the /signup page. How can we get this result in R?

1 Answers

It would be helpful if you dput() the sample table. Something like this is probably what you looking for:

library(dplyr)

df %>%
  arrange(VisitrID,startTime) %>%
  group_by(VisitorID) %>%
  summarise(
    pages_visited_before_signup = length(pagePath.y[startTime < startTime[pagePath.y == '/signup']])
  )
Related