【问题标题】:dplyr count without qoutes不带引号的 dplyr 计数
【发布时间】:2018-03-06 20:10:04
【问题描述】:

我想知道为什么 dplyr 会产生两个不同的输出

df <- data.frame("A" = 1:10, "B" = 1:10, "C" = 1:10)    
df %>% select("A") %>%  count("A")
# A tibble: 1 x 2
  `"A"`     n
  <chr> <int>
1 A        10


df %>% select(A) %>%  count(A)
# A tibble: 10 x 2
       A     n
   <int> <int>
 1     1     1
 2     2     1
 3     3     1
 4     4     1
 5     5     1
 6     6     1
 7     7     1
 8     8     1
 9     9     1
10    10     1

在这种情况下,我需要第二个。我正在构建一个闪亮的应用程序,其名称带有

selectInput("variables", 
                  choices = names(df), 
                  selected = "A", 
                  multiple = TRUE)

然后使用此输入创建一个带有df %&gt;% select(input$variables) %&gt;% count(input$variables) 的汇总表,但结果是第一个输出。

【问题讨论】:

标签: r shiny dplyr


【解决方案1】:

使用最新版本的dplyr (>0.7),您应该使用新的 tidyeval 语法。

# varname <- input$variables
varname <- "A"
df %>% select(!!as.name(varname)) %>%  count(!!as.name(varname))

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 2015-03-13
    • 1970-01-01
    • 2019-11-03
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    相关资源
    最近更新 更多