I obtain the error "Result 1 must be a single double, not a double vector of length 4"

Hi

I asked on stack overflow for assistance on how to use R to match data based on some distance criteria between two databases. The original question is here: How to match items in R based on some criteria? - Stack Overflow

Using a toy database, this worked without issue.

However, extending to a much larger database, I obtain the following error:

Error: Problem with `mutate()` column `cr`.
i `cr = map(data, addCrit, df2)`.
x Problem with `mutate()` column `crit`.
i `crit = map_dbl(data, crit, df_1)`.
x Result 1 must be a single double, not a double vector of length 4
Run `rlang::last_error()` to see where the error occurred.

Does anyone know what this error refers to and how I can solve for it?

Thanks

Welcome. Did you run rlang::last_error()?

perhaps adding logging would help you isolate the problematic data ?
Something like adding print statements. then looking to see the last one that attempted but failed.

addCrit = function(df_1, df_2){
  print("addCrit:attempting to process")
  print(head(df1))
  print(head(df2))
  r <- df_2 %>% 
    filter(type1==df_1$type1 & type2==df_1$type2) %>% 
    nest(data=criteria1:criteria4) %>% 
    mutate(
      crit = map_dbl(data, crit, df_1),
      id2 = id
    ) %>% 
    arrange(crit) %>% 
    select(id2, crit) %>% 
    head(1)
  print("addCrit: Done")
  r
}

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.