This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A top priority for making DataFrames useful in Julia is the development of | |
# good documentation and a nice API for doing plyr+reshape style operations | |
# in Julia. This Gist is a draft of such documentation. | |
load("DataFrames") | |
using DataFrames | |
load("RDatasets") | |
baseball = RDatasets.data("plyr", "baseball") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MacroTools: postwalk | |
function missing_check(es) | |
if length(es) == 0 | |
false | |
elseif length(es) == 1 | |
Expr(:call, :ismissing, es[1]) | |
elseif length(es) == 2 | |
Expr( | |
:call, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ExpressionThunk | |
source::Any | |
thunk::Any | |
end | |
macro thunk(e) | |
quote | |
ExpressionThunk( | |
$(QuoteNode(e)), | |
() -> $(esc(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = [1, 2] | |
y = [3, 4] | |
z = [x, y] | |
z′ = copy(z) | |
z′[1] === x | |
import DataFrames: DataFrame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Plots | |
r = range(0.0, 1.0, length=512) | |
p = Plots.plot( | |
r, | |
x -> x^2 * (1 - x)^2, | |
) | |
Plots.png(p, "output2.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/Rscript | |
png("output.png") | |
curve(x^2 * (1 - x)^2, from = 0, to = 1) | |
dev.off() | |
# time Rscript example.R | |
# null device | |
# 1 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RCall: @R_str | |
function runtimes(n_reps) | |
times = Array{Float64}(undef, n_reps) | |
x = rand(10_000_000) | |
for i in 1:n_reps | |
times[i] = @elapsed sum(x) | |
end | |
times | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> library("stringr") | |
> str_sub("ñ", start = -1) | |
[1] "̃" | |
> str_sub("ñ", start = -1) | |
[1] "ñ" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prob_f64(n) | |
s = 0 | |
for _ in 1:n | |
z_i = rand(UInt) | |
x_i = reinterpret(Float64, z_i) | |
s += Int(x_i == x_i + 1.0) | |
end | |
s, n | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prob(n) | |
s = 0 | |
for _ in 1:n | |
x_i = rand(UInt) | |
s += Int(Float64(x_i) === Float64(x_i + 1)) | |
end | |
s, n | |
end | |
prob(1_000_000) |