1

I cannot provide a reproducible example without sharing private data. Since I do not know why this happens I cannot imitate data to reproduce either.

I have a dplyr transformation on a data frame:

combined_grp <- combined %>% 

  mutate(temp = 1) %>% 
  pivot_wider(names_from = TTI_Bin_John, 
              names_prefix = "TTI_",
              values_from = temp,
              values_fn = as.numeric,
              values_fill = list(temp = 0))

This returns a warning:

Warning message:
Values in `temp` are not uniquely identified; output will contain list-cols.
* Use `values_fn = list(temp = list)` to suppress this warning.
* Use `values_fn = list(temp = length)` to identify where the duplicates arise
* Use `values_fn = list(temp = summary_fun)` to summarise duplicates

I tried mutating the output columns by adding this at the end of the block above:

%>% mutate_at(vars(matches("TTI_(<|>)")), as.numeric)

But this throws an error:

Error in values_fn[[value]] : object of type 'builtin' is not subsettable

Does anyone recognize this error or how I can get around it so that the new features that were pivoted wider are numeric and not lists?

Doug Fir
  • 17,940
  • 43
  • 142
  • 263

1 Answers1

0

The error message tells you that you need to modify the values_fn line.

Values in `temp` are not uniquely identified; output will contain list-cols.
* Use `values_fn = list(temp = list)` to suppress this warning.
* Use `values_fn = list(temp = length)` to identify where the duplicates arise
* Use `values_fn = list(temp = summary_fun)` to summarise duplicates

What happens if you wrap your as.numeric function in a list as in:

values_fn = list(temp = as.numeric)
Omar Wasow
  • 1,498
  • 19
  • 21