I am trying clean variables in a dataset, creating a new table variable, but splitapply does not seam to allow for nonscalar outputs of the function.
As a minimal working example, I have a table
myTable = table();
myTable.Gender = ["Male","Female","Male","Female"]';
myTable.Var1 = [1,2,3,4]';
And I am now trying to create a new table variable where the group mean is subtracted from "Var1" (yielding Var2 = [-1, -1, 1, 1])
When using splitapply(), I get the error
Error using splitapply (line 132)
The function '...' returned a non-scalar value when applied to the 1st group of data.
Is there a way to do this, also for function more involved than demeaning the input variables?
Thanks in advance,