是否可以将if()
语句嵌套在dplyr filter()
这是否有效(看起来不像)
library(dplyr)
library(shiny)
//不起作用
sample_data %>%
filter(if(input$device != "All") {Device == input$device},
if(input$channel != "All") {Channel == input$channel},
if(input$landing != "All") {Landing == input$landing}
)
相反:
// works
sample_data %>%
filter(Device == input$device,
Channel == input$channel,
Landing == input$landing
)
这样做的规定方式是什么?我想让我的过滤器有条件