Page Visits Funnel

I’m having an error:

Error in eval(lhs, parent, parent): object 'all_data' not found

This is due to this:

all_data <- all_data %>%
  mutate(time_to_purchase = purchase_time - visit_time)

Can you explain to me what I should change so it can work properly?

Please post a link to the lesson or project page. Thanks,

https://www.codecademy.com/courses/learn-r/projects/r-page-visits-funnel

1 Like

Not familiar with R but going through the unit on Joining Tables to see if anything jumps out.

We will probably need to see all your code to this point. Please post that in a new post.

That’s not what we need. We need the raw code in text form, formatted.

---
title: "Page Visits Funnel"
output: html_notebook
---

```{r message = FALSE, error=TRUE}
# load packages
library(readr)
library(dplyr)
# load data
visits <- read_csv("visits.csv")
cart <- read_csv("cart.csv")
checkout <- read_csv("checkout.csv")
purchase <- read_csv("purchase.csv")
# inspect data frames
head(visits)
head(cart)
head(checkout)
head(purchase)
# define visits_cart here:
visits_cart <- visits %>%
  left_join(cart)
visits_cart


# define total_visits here:
total_visits = nrow(visits)
total_visits

# define visit_no_cart here:
visit_no_cart <- visits_cart %>%
  filter(is.na(cart_time))
visit_no_cart

visit_no_cart_count <- nrow(visit_no_cart)
visit_no_cart_count
# calculate visit_no_cart_percent here:
visit_no_cart_percent <- visit_no_cart_count/total_visits
visit_no_cart_percent

# define cart_checkout here:
cart_checkout <- cart %>% 
  left_join(checkout)
cart_checkout


# define total_carts here:
total_carts = nrow(cart)
total_carts

# define cart_no_checkout here:
cart_no_checkout <- cart_checkout %>% 
   filter(is.na(checkout_time))
cart_no_checkout

cart_no_checkout_count <- nrow(cart_no_checkout)
cart_no_checkout_count
# calculate cart_no_checkout_percent here:
cart_no_checkout_percent <- cart_no_checkout_count/total_carts
cart_no_checkout_percent
# define all_data here:
all_data <- all_data %>%
  mutate(time_to_purchase = purchase_time - visit_time)
head(all_data)


# define total_checkout here:


# define checkout_no_purchase here:




# calculate checkout_no_purchase_percent here:


# update all_data with time_to_purchase column here:


# inspect the updated all_data data frame here:

# define time_to_purchase here:



1 Like

This is defining all_data, so what variable should be on the right side?

All the data that has been calculated, so far.

Your issue is here

you’re trying to pipe all_data in when all_data hasn’t been defined yet. Piping is a useful tool in r but since all_data hasn’t actually been defined yet, so you’re trying to mutate the column time_to_purchase on a data frame that doesn’t exist yet. You need to define all_data initially through what I believe in the exercise is left joining all your stages together, then you can execute that step.

1 Like

How do I do that, exactly?

Right here you create visits_cart by doing a left join of cart onto visits. for all_data you just want to do a similar thing but by doing a left_join of all the steps, one after another aka.
visits -> cart -> checkout -> purchase.

That is seems very confusing to me.

You’re just taking what you’ve already done and stacking it up, so what you end up with is

all_data <- visits %>%
  left_join(cart) %>%
  left_join(checkout) %>%
  left_join(purchase)

and that’s all_data defined! Then your code you originally had the issue with should work fine.

It worked, thanks bro.

I’m having a new issue with the time_to_purchase:

time_to_purchase <- all_data %>%
  summarize(mean_time = mean(time_to_purchase, na.rm = TRUE))
time_to_purchase

This is the error I get:

# update all_data with time_to_purchase column here:
time_to_purchase <- all_data %>%
  summarize(mean_time = mean(time_to_purchase, na.rm = TRUE))

Error in mean(time_to_purchase, na.rm = TRUE): object 'time_to_purchase' not found
time_to_purchase
Error in eval(expr, envir, enclos): object 'time_to_purchase' not found

Can I see the code you have used for adding the time_to_purchase column into the all_data dataset.

Oh yeah, I completely get you. What should I replace all_data with?

You don’t need to replace all_data, your code is correct in its current state. The issue is you haven’t added the time_to_purchase column into all_data which should have been done in a previous step.

What should be included when making a time_to_purchase column. Since I don’t think I have made that yet.