← 返回 Tessera▶数据预览前 6 行
| model | mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb |
|---|
| Mazda RX4 | 21.0 | 6 | 160.0 | 110 | 3.9 | 2.62 | 16.5 | 0 | 1 | 4 | 4 |
| Mazda RX4 Wag | 21.0 | 6 | 160.0 | 110 | 3.9 | 2.88 | 17.0 | 0 | 1 | 4 | 4 |
| Datsun 710 | 22.8 | 4 | 108.0 | 93 | 3.85 | 2.32 | 18.6 | 1 | 1 | 4 | 1 |
| Hornet 4 Drive | 21.4 | 6 | 258.0 | 110 | 3.08 | 3.21 | 19.4 | 1 | 0 | 3 | 1 |
| Hornet Sportabout | 18.7 | 8 | 360.0 | 175 | 3.15 | 3.44 | 17.0 | 0 | 0 | 3 | 2 |
| Valiant | 18.1 | 6 | 225.0 | 105 | 2.76 | 3.46 | 20.2 | 1 | 0 | 3 | 1 |
变量12 列
| # | 变量 | 类型 | 缺失 | 统计 |
|---|
| 1 | modelCar model name, kept from the original row names. | 字符型 | — | 不同值 32Mazda RX4 · Mazda RX4 Wag · Datsun 710 · Hornet 4 Drive · Hornet Sportabout · Valiant · Duster 360 · Merc 240D |
| 2 | mpgkeyMiles per US gallon. | 双精度 | — | min 10.4q1 —中位 19.2均值 20.1q3 —max 33.9 |
| 3 | cylNumber of cylinders. | 整数 | — | min 4q1 —中位 6均值 6.19q3 —max 8 |
| 4 | dispDisplacement in cubic inches. | 双精度 | — | min 71.1q1 —中位 196.3均值 230.7q3 —max 472.0 |
| 5 | hpGross horsepower. | 整数 | — | min 52.0q1 —中位 123.0均值 146.7q3 —max 335.0 |
| 6 | dratRear axle ratio. | 双精度 | — | min 2.76q1 —中位 3.7均值 3.6q3 —max 4.93 |
| 7 | wtWeight in thousands of pounds. | 双精度 | — | min 1.51q1 —中位 3.33均值 3.22q3 —max 5.42 |
| 8 | qsecQuarter-mile time in seconds. | 双精度 | — | min 14.5q1 —中位 17.7均值 17.8q3 —max 22.9 |
| 9 | vs0 is a V engine. 1 is a straight engine. | 整数 | — | min 0q1 —中位 0均值 0.406q3 —max 1 |
| 10 | am0 is automatic. 1 is manual. | 整数 | — | min 0q1 —中位 0均值 0.406q3 —max 1 |
| 11 | gearNumber of forward gears. | 整数 | — | min 3q1 —中位 4均值 3.69q3 —max 5 |
| 12 | carbNumber of carburettors. | 整数 | — | min 1q1 —中位 2均值 2.81q3 —max 8 |
载入已写好列类型
library(readr)
mtcars <- read_csv(
"https://assets.evanzhou.org/tessera/csv/mtcars.csv",
col_types = cols(
model = col_character(),
mpg = col_double(),
cyl = col_integer(),
disp = col_double(),
hp = col_integer(),
drat = col_double(),
wt = col_double(),
qsec = col_double(),
vs = col_integer(),
am = col_integer(),
gear = col_integer(),
carb = col_integer()
)
)
URLhttps://assets.evanzhou.org/tessera/csv/mtcars.csv
Source
R 自带的 datasets::mtcars,来自 1974 年美国《Motor Trend》杂志。32 款汽车包含燃油效率、气缸数、排量、马力、重量和变速器等 11 个数值变量。
原数据把车型名存在行名里;这里导出时将其保留为 model 列,其余变量和值不变。完整变量定义见 R 官方文档。
Use cases
- 相关性热图:同时比较多项性能指标的正负相关结构
- 散点矩阵:回到具体变量对检查形态与离群点
- 平行坐标:比较不同车型的多指标轮廓
- 聚类热图:按整体性能结构重排车型或变量
▶生成脚本R · 21 行
# 产物写到 ../csv/mtcars.csv —— 脚本和 CSV 是 content/tessera/data/ 下固定的兄弟目录,
# 所以按脚本自身定位,不依赖你在哪个目录敲这条命令。csv/ 不进仓库(见 .gitignore)。
#
# Rscript 时路径在 --file= 里,source() 时在 sys.frame()$ofile 里,两种都要认:
# 只取其中一种的话,另一种跑法会静默地把 CSV 写到当前目录去。
script_dir <- local({
arg <- grep("^--file=", commandArgs(trailingOnly = FALSE), value = TRUE)
path <- if (length(arg)) sub("^--file=", "", arg[[1L]]) else sys.frame(1)$ofile
dirname(normalizePath(path, mustWork = TRUE))
})
out_csv <- file.path(script_dir, "..", "csv", "mtcars.csv")
dir.create(dirname(out_csv), recursive = TRUE, showWarnings = FALSE)
d <- cbind(model = rownames(datasets::mtcars), datasets::mtcars)
write.csv(
d,
out_csv,
row.names = FALSE,
quote = FALSE
)
表中统计由 scripts/profile_dataset.py 于 2026-08-11 数出。