Row-wise mean of columns in a DataFrame

Definitely don’t do this. It will allocate tons of memory.

You want

transform(df, AsTable(:) => ByRow(mean) => :rowmean)

BTW, are you coming from Stata by chance? This is a common operation in Stata.

Also, the above will run into trouble if you have many many columns because it constructs a named tuple. Making it better has been the object of extensive discussion. See here.

1 Like