问题
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