我试图让 expss use_labels 与 dplyr 逻辑一起使用 - 请参见下面的示例。
小插图在 use_labels 下声明了以下内容。到目前为止,变量标签仅支持将在 data.frame 中评估的表达式。这是我在这里遇到的问题吗?
###########################################
library(expss)
library(tidyverse)
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (1000 lbs)",
qsec = "1/4 mile time",
vs = "Engine",
vs = c("V-engine" = 0,
"Straight engine" = 1),
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
# table with caption from label - labels working
cro_cpct(mtcars$am, mtcars$vs) %>% set_caption(var_lab(mtcars$am))
## This works as expected - now to get this with expss use_labels.
mtcars %>%
group_by(am) %>%
summarise(
freq = n()
)
#######
#am freq
#<labelled> <int>
# 1 0 19
# 2 1 13
########################
#### This doesn't work - i.e. not labelled
use_labels(mtcars %>%
group_by(am) %>%
summarise(
freq = n()
))
## Error in substitute_symbols(expr, c(substitution_list, list(..data = quote(expss::vars(other))))) :
# argument "expr" is missing, with no default
如果标签不能与 dplyr 逻辑一起使用,有人知道另一个可以用 dplyr 做标签的包吗?问候