Do you really want a cumulative sum on the rows? From your code it looks that you rather want a linear combination of columns…
Here are some ways to do a linear combination of columns. In these examples we want to combine columns 2,3,4 with respective weights 10,1,0:
julia> weights = [10, 1, 0];
julia> df = DataFrame(rand(0:9, 3, 4), :auto)
3×4 DataFrame
Row │ x1 x2 x3 x4
│ Int64 Int64 Int64 Int64
─────┼────────────────────────────
1 │ 9 4 5 6
2 │ 1 2 3 9
3 │ 2 3 4 2
One way is using linear algebra, putting the columns in a matrix:
df.cumValue = Array(df[!, 2:end]) * weights
# or
transform(df, 2:4 => ((cols...) -> hcat(cols...) * weights) => :cumValue)
# result:
3×5 DataFrame
Row │ x1 x2 x3 x4 cumValue
│ Int64 Int64 Int64 Int64 Int64
─────┼──────────────────────────────────────
1 │ 9 4 5 6 45
2 │ 1 2 3 9 23
3 │ 2 3 4 2 34
Another way is to implement the linear combination with mapreduce
:
transform(df, 2:4 => ((c...) -> mapreduce(*, +, c, weights)) => :cumValue)
I think the best is to define the linear combination as a function:
linear_combination(weights) = (cols...) -> mapreduce(*, +, cols, weights)
transform(df, 2:4 => linear_combination(weights) => :cumValue)