getting error stating “Error: `x` must be a formula”

时光总嘲笑我的痴心妄想 提交于 2020-06-28 05:42:07

问题


I am using the qwraps2 package that has the summary_table function. For some reason I am getting the error "Error: x must be a formula" when I run the code below.

args(summary_table)

summary_table(death_vs_gender, summaries = qsummary(death_vs_gender))

our_summary1 <- list("Table 2: Summary Statistics for Mass 
Shooting Deaths in American between 
1966-2017 by Men & Women" = list(
                             "n" = sum(death_vs_gender$Deaths),
                             "Min" = ~ min(death_vs_gender$Deaths),
                             "Max" = ~ max(death_vs_gender$Deaths),
                             "Median" = ~ median(death_vs_gender$Deaths),
                             "Mean" = ~ mean(death_vs_gender$Deaths),
                             "Std. Dev." = ~ sd(death_vs_gender$Deaths)))


whole <- summary_table(death_vs_gender, our_summary1)
whole

回答1:


There appears to be an ~ omitted from the line "n" = sum(death_vs_gender$Deaths),.

Try the following:

our_summary1 <- 
  list("Table 2: Summary Statistics for Mass Shooting Deaths in American between 1966-2017 by Men & Women" = 
       list(
            "n"         = ~ sum(.data$Deaths),
            "Min"       = ~ min(.data$Deaths),
            "Max"       = ~ max(.data$Deaths),
            "Median"    = ~ median(.data$Deaths),
            "Mean"      = ~ mean(.data$Deaths),
            "Std. Dev." = ~ sd(.data$Deaths)
           )
      )

Note that the name death_vs_gender has been replaced with .data, the data pronoun in the tidyverse. This is an important change. Using the pronoun will will help prevent errant results due to scoping issues.



来源:https://stackoverflow.com/questions/58615857/getting-error-stating-error-x-must-be-a-formula

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!