Hi everyone! I’m brand new to Julia (and fairly new to coding in general). I’m currently trying to write a function that will edit an object of type DataFrame to make it workable for the Ripserer package. The function works when I just pass in the data frame… however, I want it to also be able to take in optional arguments for how much of the original data frame I want to keep… and that’s where I am encountering issues. I think it has to do with the variable types I declare at the beginning of the function, but I’m not sure. Here’s my function:
function prep_data(df, starting_row::Int64 = -1, ending_row::Int64 = -1, starting_col::Int64 = -1, ending_col::Int64 = -1)
if (starting_row != -1 && ending_row != -1)
row_temp = df[:starting_row:ending_row, :]
elseif (starting_row == -1 && ending_row == -1)
row_temp = df
else print("Invalid input. If a starting_row val is given, an ending_row val must be given as well.")
end
if (starting_col != -1 && ending_col != -1)
col_temp = row_temp[:, :starting_col:ending_col]
elseif (starting_col == -1 && ending_col == -1)
col_temp = row_temp
else print("Invalid input. If a starting_col val is given, an ending_col val must be given as well")
end
y = transpose(Array(col_temp))
z = [tuple(y[:,c]...) for c in 1:size(y, 2)]
return z
end
From what I’ve gathered, using starting_row (or the other variable names for that matter) inside of the brackets for parsing the DataFrame is causing the error. Here’s the error message I’m getting:
MethodError: no method matching (::Colon)(::Symbol, ::Int64)
Closest candidates are:
(::Colon)(::T, ::Any, ::T) where T at range.jl:40
(::Colon)(::T, ::Real, ::T) where T<:AbstractFloat at range.jl:18
(::Colon)(::T, ::T) where T<:Real at range.jl:5
…
Stacktrace:
[1] prep_data(df::DataFrame, starting_row::Int64, ending_row::Int64, starting_col::Int64, ending_col::Int64)
@ Main .\In[49]:4
[2] top-level scope
@ In[50]:1
[3] eval
@ .\boot.jl:360 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1116