This article describes how to create a table that represents the concept of a brand funnel (similar to a purchase funnel) using R code. For an approach that doesn't use code, see: How to Create a Funnel or Pyramid Chart.
Requirements
You will need to create the following output tables:
- Awareness
- Consideration (including Top 2 Box NET category)
- Preferred brand/item
Method
Add your data
Set up your source tables
The easiest way to create the statistics we need for the funnel is to create tables in Displayr. This is done by dragging from the Data Sources section on to your page.
We later reference certain cells within those tables and rearrange them in the final summary table. For the worked example, I created three tables upfront, shown below:
Create an R Output
- From the toolbar, click Calculation > Custom Code.
- Paste the following into the R Code editor:
# Set the name of the brands
brands <- c("Coca-Cola","Diet Coke","Coke Zero","Pepsi","Diet Pepsi","Pepsi Max")
# Pull in the tables that will be used to create the brand funnel table
aware <- table.Awareness[brands]
consider <- table.Brand.consider[brands,"NET: Top 2 Box"]
main <- table.Preferred.cola[brands]
# Combine the tables into a single table and rename the rows
table <- cbind("Awareness" = aware, "Consider" = consider, "Preferred" = main)
# Set which output the funnel will use
funnel <- t(table)
# Create ratio calculation
ratio <- funnel["Consider",]/funnel["Preferred",]
# Add calculated output to the table and name the row
funnel <- rbind(funnel, "Ratio" = ratio)
In this example, I am using data that contains cola brands. You will need to update the brands on the first line of code to match your data. Lines 5-7 reference the tables that were created as part of the requirements. To find the table names for the aware, consider, and main inputs, select each table on your page, and from the object inspector, go to General > General > Name.
Next
How to Work with R in Displayr
How R Works Differently in Displayr Compared to Other Programs
How to Import a Data Set Using R
How to Create a Custom Numeric R Variable
How to Create a Custom R Text Variable
How to Add a Custom Calculation
How to Work with R Data Types and Structures
How to Reference and Distinguish between Different R Objects in Displayr
How to Work with Conditional R Formulas
How to Perform Mathematical Calculations Using R
How to Work with Regular Expressions Using R
How to Use R's Paste Formulas in Displayr
How to Extract Information from an R Object