3
votes

I'm getting Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘n’ for signature ‘"missing"’ and I wasn't able to figure out where the problem is.

I'm following the example Visualizing the Customer Journey with R and Adobe Analytics Data Feeds by Trevor Paulsen with my own data. I'm providing an example of my data below.

library(dplyr)
library(plotly)

##data example
newdata <- data.frame(customer_id = c(
10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133
,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133
,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133
,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133
,10002133,10002133,10002133,10002133,10002133,10002133,10002133,10002133)
,f_ev = c('hb - transferencias','hb - transferencias','hb - error acceso transferencias'
,'hb - error acceso error app transferencias','hb - error acceso'
,'hb - consulta transferencias','hb - consulta transferencias','hb - consulta transferencias'
,'hb - consulta transferencias','hb - consulta transferencias','hb - consulta transferencias'
,'hb - consulta transferencias','hb - consulta transferencias','hb - consulta transferencias'
,'hb - consulta transferencias','hb - consulta transferencias','hb - consulta transferencias'
,'hb - consulta transferencias','hb - consulta transferencias','hb - consulta transferencias'
,'hb - consulta transferencias','hb - consulta pago transferencias','hb - consulta pago transferencias'
,'hb - consulta pago transferencias','hb - consulta pago','hb - consulta pago'
,'hb - consulta error app transferencias','hb - consulta error app transferencias'
,'hb - consulta error app transferencias','hb - consulta error app pago transferencias'
,'hb - consulta error app','hb - consulta error acceso transferencias','hb - consulta'
,'hb - consulta','hb - consulta','hb - consulta','hb - consulta','hb - consulta'
,'hb - consulta','hb - consulta','hb - consulta','hb - consulta','hb - consulta'
,'hb - consulta','hb - consulta','hb - consulta','hb - consulta'
,'hb - alerta producto o servicio consulta transferencias','hb - alerta producto o servicio consulta error app'
,'hb - alerta producto o servicio consulta','hb - alerta producto o servicio consulta'
,'hb - alerta producto o servicio consulta')
,conversion = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
,order_seq = c(52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20
,19,18,17,16,15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
)

##path generation
paths_stacks = newdata %>% 
  group_by(customer_id) %>% 
  summarize(path = paste0(f_ev, collapse =  " > "),
            conversion = max(conversion)) %>% 
  ungroup() %>%
  group_by(path) %>%
  summarize(
    conversion = sum(conversion),
    path_count = n()
  ) %>% ungroup() %>%
  mutate(
    conversion_rate = conversion/path_count
  ) 

The result is an error:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘n’ for signature ‘"missing"’

1
Example does not work in my case. It seems commas are missing...Christoph
@Christoph, yap, you're right, thanks. I corrected the commasOscar Benitez

1 Answers

2
votes

Solved! I have the SparkR library in my script that masks functions with the same name as dplyr's. Correcting the script with the appropriate library, it works without problems

##corrected script
paths_stacks = newdata %>% 
  dplyr::group_by(customer_id) %>% 
  dplyr::summarize(path = paste0(f_ev, collapse =  " > "),
            conversion = max(conversion)) %>% 
  dplyr::ungroup() %>%
  dplyr::group_by(path) %>%
  dplyr::summarize(
    conversion = dplyr::sum(conversion),
    path_count = dplyr::n()
  ) %>% ungroup() %>%
  dplyr::mutate(
    conversion_rate = conversion/path_count
  )