Skip to content

Instantly share code, notes, and snippets.

@nalimilan
Created October 13, 2018 10:01
Show Gist options
  • Save nalimilan/a98ca41e0d5933e5a42281d5bd442135 to your computer and use it in GitHub Desktop.
Save nalimilan/a98ca41e0d5933e5a42281d5bd442135 to your computer and use it in GitHub Desktop.
function f(cols)
x = 0.0
for i in 1:length(cols[1])
t = ntuple(j -> cols[j][i], length(cols))
x += t[1]
end
x
end
function g(cols, names)
x = 0.0
for i in 1:length(cols[1])
t = ntuple(j -> cols[j][i], length(cols))
nt = NamedTuple{names,typeof(t)}(t)
x += nt.x
end
x
end
using DataFrames
df = DataFrame(x=rand(1000), y=rand(1000))
df2 = DataFrame(rand(1000, 100))
df2.x = rand(1000)
f(tuple(DataFrames.columns(df)...))
f(tuple(DataFrames.columns(df2)...))
g(tuple(DataFrames.columns(df)...), tuple(names(df)...))
g(tuple(DataFrames.columns(df2)...), tuple(names(df2)...))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment