在dplyr的group_by中使用对象代替列名

时间:2018-11-09 10:30:55

标签: r dplyr evaluation

我想输入一个可以在此之前声明的输入:

GroupVar2 = recommendation$Product

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

但是,我收到“列GroupVar2未知”的错误。

有人知道如何使用占位符中指定的“ recommendation $ Product”吗?

1 个答案:

答案 0 :(得分:2)

由于 Error: connect ETIMEDOUT [0] at Connection._handleConnectTimeout (C:\Watson\data-cap\node_modules\mysql\lib\Connection.js:411:13) [0] at Object.onceWrapper (events.js:313:30) [0] at emitNone (events.js:106:13) [0] at Socket.emit (events.js:208:7) [0] at Socket._onTimeout (net.js:407:8) [0] at ontimeout (timers.js:475:11) [0] at tryOnTimeout (timers.js:310:5) [0] at Timer.listOnTimeout (timers.js:270:5) [0] -------------------- [0] at Protocol._enqueue (C:\Watson\data-cap\node_modules\mysql\lib\protocol\Protocol.js:144:48) [0] at Protocol.handshake (C:\Watson\data-cap\node_modules\mysql\lib\protocol\Protocol.js:51:23) [0] at Connection.connect (C:\Watson\data-cap\node_modules\mysql\lib\Connection.js:118:18) [0] at Connection._implyConnect (C:\Watson\data-cap\node_modules\mysql\lib\Connection.js:453:10) [0] at Connection.query (C:\Watson\data-cap\node_modules\mysql\lib\Connection.js:198:8) [0] at Object.<anonymous> (C:\Watson\data-cap\db.js:26:12) [0] at Module._compile (module.js:643:30) [0] at Object.Module._extensions..js (module.js:654:10) [0] at Module.load (module.js:556:32) [0] at tryModuleLoad (module.js:499:12) 在数据帧group_by中寻找列GroupVar2而产生错误。

如果需要使用占位符recommendation,则可以使用 GroupVar2 取消引用 !!中的参数:< / p>

group_by

通过这种方式评估输入。