Adding calculated columns to dataframe

You can simplify it like this:

using DataFrames
using Statistics

DF = DataFrame(ID = 1:10, Col1 = rand(15:0.01:40,10),
                          Col2 = rand(30:0.01:55,10),
                          Col3 = rand(20:0.01:65,10))

round3(x) = round(x, digits=3)

transform(DF, AsTable(2:4) .=>
              ByRow.([minimum, maximum, round3∘var, round3∘std]) .=>
              [:Min, :Max, :Var, :StdDev])

# Output
10×8 DataFrame
 Row │ ID     Col1     Col2     Col3     Min      Max      Var      StdDev  
     │ Int64  Float64  Float64  Float64  Float64  Float64  Float64  Float64 
─────┼──────────────────────────────────────────────────────────────────────
   1 │     1    16.83    40.6     41.94    16.83    41.94  199.553   14.126
   2 │     2    39.26    51.72    42.11    39.26    51.72   42.621    6.528
   3 │     3    16.8     46.58    36.69    16.8     46.58  230.045   15.167
   4 │     4    31.01    48.33    46.44    31.01    48.33   90.273    9.501
   5 │     5    35.92    41.29    39.67    35.92    41.29    7.587    2.755
   6 │     6    23.63    54.91    29.67    23.63    54.91  275.33    16.593
   7 │     7    38.69    38.05    47.62    38.05    47.62   28.623    5.35
   8 │     8    32.24    38.45    30.99    30.99    38.45   15.963    3.995
   9 │     9    36.48    35.7     24.4     24.4     36.48   45.704    6.76
  10 │    10    15.17    49.39    35.62    15.17    49.39  296.471   17.218
1 Like