-
-
Save nalimilan/a98ca41e0d5933e5a42281d5bd442135 to your computer and use it in GitHub Desktop.
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 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