This should be a relatively simple question but I could not find a great answer. I have a dataframe like below ( but with way more colums), and I wish to add a new column that is the sum of all the other columns (e.g. a + b + c). We can assume that all of the columns are float64 types. I would like to do this over a large group of columns so specifying each column one by one is not feasible. Many thanks!
df = DataFrame(a = repeat([1, 2, 3, 4], outer=[2]),
b = repeat([2, 1], outer=[4]),
c = randn(8))
sum(eachcol(df)) does indeed sum across, since it essentially does sum([df[!, c] for c in names(df)]). If you want to sum down, you should use sum.(eachcol(df)), which is essentially [sum(df[!, c]) for c in names(df)].