【发布时间】:2021-05-23 21:35:33
【问题描述】:
数据集非常广泛,是否可以使用可变标签来选择列?
library(expss)
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"
)
mtcars %>%
select(contains("Miles"))
这不起作用,因为它在列名中查找。它可以改为查看标签吗?
编辑:我应该补充一下,除了将标签转换为列名这一点很明显。
【问题讨论】: