1

I would like to have an input that I can state before like so:

GroupVar2 = recommendation$Product

prof.prod <- recommendation %>% group_by(GroupVar2) %>% summarise(value = 
sum(Revenue)) %>% filter(value==max(value))

However, I get the error that the "Column GroupVar2 is unknown".

Does anyone know how to use 'recommendation$Product' specified in a placeholder?

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
nemja
  • 459
  • 4
  • 19
  • Please give a [mcve]. See [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/4996248) for what this would mean in R. – John Coleman Nov 09 '18 at 10:32

1 Answers1

3

The error arises because group_by is looking for column GroupVar2 in the data frame recommendation.

If you need to use the placeholder GroupVar2, you can use !! to unquote the argument in group_by:

group_by(!! GroupVar2)

In this way the input is evaluated.

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
  • Thanks Sven! But I would like to use it in a sat up that I can use for multiple data sets. So if the column is not named 'recommendation' I would like it to work still. – nemja Nov 09 '18 at 10:38