Input data
Build two tables, then write them as CSV
A Table literal builds a small table directly from
column arrays. Here it also gives us convenient input files for the
rest of the guide. The cars table is inspired by R's
mtcars dataset.
import "csv";
let sample_cars = Table {
car = ["Mazda RX4", "Hornet 4 Drive", "Duster 360", "Merc 240D",
"Fiat 128", "Toyota Corolla", "Camaro Z28", "Volvo 142E"],
maker_id = [1, 2, 2, 3, 4, 5, 6, 7],
mpg = [21.0, 21.4, 14.3, 24.4, 32.4, 33.9, 13.3, 21.4],
cyl = [6, 6, 8, 4, 4, 4, 8, 4],
hp = [110, 110, 245, 62, 66, 65, 245, 109],
wt = [2.620, 3.215, 3.570, 3.190, 2.200, 1.835, 3.840, 2.780],
am = [1, 0, 0, 0, 1, 1, 0, 1]
};
let sample_makers = Table {
maker_id = [1, 2, 3, 4, 5, 6, 7],
maker = ["Mazda", "AMC", "Mercedes", "Fiat", "Toyota", "Chevrolet", "Volvo"]
};
write_csv(sample_cars, "cars.csv");
write_csv(sample_makers, "makers.csv");