mydf = DataFrame(a = [1,2,3], b = [1, missing, 2])
Works:
mydf = transform(mydf,
AsTable([:a, :b])
=> ByRow(x -> x.a + x.b ) => :c)
Works:
mydf = transform(mydf,
AsTable([:a, :b])
=> ByRow(x -> sum(x) ) => :c)
Doesn’t work. But in some cases it is convenient to use the numerical index rather than repeat the column names:
mydf = transform(mydf,
AsTable([:a, :b])
=> ByRow(x -> sum(x[1:2]) ) => :c)
ERROR: MethodError: no method matching getindex(::NamedTuple{(:a, :b),Tuple{Int64,Union{Missing, Int64}}}, ::UnitRange{Int64})
Closest candidates are:
getindex(::NamedTuple, ::Int64) at namedtuple.jl:112
getindex(::NamedTuple, ::Symbol) at namedtuple.jl:113
Stacktrace:
[1] (::var"#359#360")(::NamedTuple{(:a, :b),Tuple{Int64,Union{Missing, Int64}}}) at ./REPL[16]:3
[2] iterate at ./generator.jl:47 [inlined]
[3] collect at ./array.jl:686 [inlined]
[4] (::ByRow{var"#359#360"})(::NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Union{Missing, Int64},1}}}) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:325
[5] default_table_transformation(::DataFrame, ::ByRow{var"#359#360"}) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selectionfast.jl:126
[6] table_transformation(::DataFrame, ::Function) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selectionfast.jl:54
[7] _transformation_helper(::DataFrame, ::AsTable, ::Base.RefValue{Any}) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:557
[8] select_transform!(::Base.RefValue{Any}, ::DataFrame, ::DataFrame, ::Set{Symbol}, ::Bool, ::Base.RefValue{Bool}, ::BitArray{1}) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:764
[9] _manipulate(::DataFrame, ::Array{Any,1}, ::Bool, ::Bool) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:1621
[10] manipulate(::DataFrame, ::Any, ::Vararg{Any,N} where N; copycols::Bool, keeprows::Bool, renamecols::Bool) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:1541
[11] select(::DataFrame, ::Any, ::Vararg{Any,N} where N; copycols::Bool, renamecols::Bool) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:1171
[12] #transform#482 at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:1238 [inlined]
[13] transform(::DataFrame, ::Any) at /home/jube/.julia/packages/DataFrames/MA4YO/src/abstractdataframe/selection.jl:1238
[14] top-level scope at REPL[16]:1