Okay thanks for this. We were definitely mis-understanding what you wanted.
I think you want combine or transform with a GroupedDataFrame. Iβm assuming you donβt just want the maximum of the KPI_1 and KPI_2 values, but rather want to make a transformation by group. This will do that
julia> using DataFramesMeta, Chain;
julia> df = DataFrame(
Item = ["a", "a", "b", "b"],
Name = ["searchLow", "searchUpp", "KPI_1", "KPI_2"],
Vel_B1_FTF = [NaN, 0.1, 0.4, NaN])
4Γ3 DataFrame
Row β Item Name Vel_B1_FTF
β String String Float64
ββββββΌβββββββββββββββββββββββββββββββ
1 β a searchLow NaN
2 β a searchUpp 0.1
3 β b KPI_1 0.4
4 β b KPI_2 NaN
julia> par = :Vel_B1_FTF;
julia> @chain df begin
groupby(:Item)
@transform max_in_group = begin
x = filter(!isnan, cols(par))
isempty(x) && return NaN
maximum(x)
end
end
4Γ4 DataFrame
Row β Item Name Vel_B1_FTF max_in_group
β String String Float64 Float64
ββββββΌβββββββββββββββββββββββββββββββββββββββββββββ
1 β a searchLow NaN 0.1
2 β a searchUpp 0.1 0.1
3 β b KPI_1 0.4 0.4
4 β b KPI_2 NaN 0.4
If you really just want the maximum of KPI_1 and KPI_2, then yeah thatβs tough.
julia> function get_max(df, vals, namevar, keys)
x = df[!, vals]
n = df[!, namevar]
inds = findall(t -> t in keys, n)
# handle empty collection as needed
maximum(filter(!isnan, x[inds]))
end;
julia> get_max(df, par, :Name, ["KPI_1", "KPI_2"])
0.4
So there are two things that make this tough in Julia, unfortunately. The first is the lack of row indexing, which you can do in Matlab I guess. The second is that Julia propagates NaNs in maximum while Matlab does not.
Propagation of NaNs in Julia is presumably governed by IEEE rules, so no changing that.
Additionally, maximum errors on an empty collection. This might actually be changeable. Maybe we should add a keyword argument for ifempty in maximum, similar to init in sum.