From 9bbcf7dcf85855d35da42599e0673b7adf1b3a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 19 Jan 2022 18:24:17 +0100 Subject: [PATCH] add exercises for chapter 7 --- appB.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/appB.jl b/appB.jl index 7db5a93..131cdab 100644 --- a/appB.jl +++ b/appB.jl @@ -130,3 +130,28 @@ using BenchmarkTools x = rand(10^6); @btime DataFrame(x=$x); @btime DataFrame(x=$x; copycols=false); + +# Code for exercise 7.2 + +df1 = DataFrame(a=1,b=2) +df2 = DataFrame(b=3, a=4) +vcat(df1, df2) +vcat(df1, df2, cols=:orderequal) + +# Code for exercise 7.3 + +function walk_unique_2ahead() + walk = DataFrame(x=0, y=0) + for _ in 1:10 + current = walk[end, :] + push!(walk, sim_step(current)) + end + return all(walk[i, :] != walk[i+2, :] for i in 1:9) +end +Random.seed!(2); +proptable([walk_unique_2ahead() for _ in 1:10^5]) + +# Code for exercise 7.4 + +@time wide = DataFrame(ones(1, 10_000), :auto); +@time Tables.columntable(wide);